From acff601d5cc2c33ab0a0dca4b7470e9fa992e85c Mon Sep 17 00:00:00 2001 From: Jigar Wala Date: Mon, 30 Oct 2023 17:06:00 +0530 Subject: [PATCH] adds and fix tests --- packages/dom/test/helpers.js | 13 +++++++++++-- packages/dom/test/serialize-dom.test.js | 25 ++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/packages/dom/test/helpers.js b/packages/dom/test/helpers.js index 2877d3404..84938e170 100644 --- a/packages/dom/test/helpers.js +++ b/packages/dom/test/helpers.js @@ -3,7 +3,7 @@ export const chromeBrowser = 'CHROME'; export const firefoxBrowser = 'FIREFOX'; // create and cleanup testing DOM -export function withExample(html, options = { withShadow: true }) { +export function withExample(html, options = { withShadow: true, invalidTagsOutsideBody: false }) { let $test = document.getElementById('test'); if ($test) $test.remove(); @@ -16,7 +16,7 @@ export function withExample(html, options = { withShadow: true }) { document.body.appendChild($test); - if (options?.withShadow) { + if (options.withShadow) { $testShadow = document.createElement('div'); $testShadow.id = 'test-shadow'; let $shadow = $testShadow.attachShadow({ mode: 'open' }); @@ -24,6 +24,15 @@ export function withExample(html, options = { withShadow: true }) { document.body.appendChild($testShadow); } + + if (options.invalidTagsOutsideBody) { + let p = document.getElementById('invalid-p'); + p?.remove(); + p = document.createElement('p'); + p.id = 'invalid-p'; + p.innerText = 'P tag outside body'; + document.documentElement.append(p); + } return document; } diff --git a/packages/dom/test/serialize-dom.test.js b/packages/dom/test/serialize-dom.test.js index 1da2d53ee..5fcecfe6f 100644 --- a/packages/dom/test/serialize-dom.test.js +++ b/packages/dom/test/serialize-dom.test.js @@ -6,7 +6,8 @@ describe('serializeDOM', () => { expect(serializeDOM()).toEqual({ html: jasmine.any(String), warnings: jasmine.any(Array), - resources: jasmine.any(Array) + resources: jasmine.any(Array), + hints: jasmine.any(Array) }); }); @@ -27,7 +28,7 @@ describe('serializeDOM', () => { it('optionally returns a stringified response', () => { expect(serializeDOM({ stringifyResponse: true })) - .toMatch('{"html":".*","warnings":\\[\\],"resources":\\[\\]}'); + .toMatch('{"html":".*","warnings":\\[\\],"resources":\\[\\],"hints":\\[\\]}'); }); it('always has a doctype', () => { @@ -68,7 +69,7 @@ describe('serializeDOM', () => { expect($('h2.callback').length).toEqual(1); }); - it('applies dom transformations', () => { + it('applies default dom transformations', () => { withExample('