From 32e144e14fc31d50b3a6b4e0aff9c2f86480d761 Mon Sep 17 00:00:00 2001 From: David Ortner Date: Wed, 10 Jan 2024 17:06:32 +0100 Subject: [PATCH] #466@trivial: Adds unit test for importNode(). --- .../happy-dom/test/fetch/SyncFetch.test.ts | 34 +++++++++---------- .../test/nodes/document/Document.test.ts | 29 ++++++++++++++-- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/packages/happy-dom/test/fetch/SyncFetch.test.ts b/packages/happy-dom/test/fetch/SyncFetch.test.ts index 7388434f8..c9938447c 100644 --- a/packages/happy-dom/test/fetch/SyncFetch.test.ts +++ b/packages/happy-dom/test/fetch/SyncFetch.test.ts @@ -2195,7 +2195,7 @@ describe('SyncFetch', () => { expect(requestCount).toBe(1); }); - it('Revalidates cache with a "If-Modified-Since" request for a GET response with "Cache-Control" set to "max-age=0.002".', async () => { + it('Revalidates cache with a "If-Modified-Since" request for a GET response with "Cache-Control" set to "max-age=0.005".', async () => { browserFrame.url = 'https://localhost:8080/'; const url = 'https://localhost:8080/some/path'; @@ -2216,7 +2216,7 @@ describe('SyncFetch', () => { 'last-modified', 'Mon, 11 Dec 2023 02:00:00 GMT', 'cache-control', - 'max-age=0.002' + 'max-age=0.005' ], data: '' } @@ -2233,7 +2233,7 @@ describe('SyncFetch', () => { 'content-length', String(responseText.length), 'cache-control', - 'max-age=0.002', + 'max-age=0.005', 'last-modified', 'Mon, 11 Dec 2023 01:00:00 GMT' ], @@ -2279,7 +2279,7 @@ describe('SyncFetch', () => { expect(headers1).toEqual({ 'content-type': 'text/html', 'content-length': String(responseText.length), - 'cache-control': `max-age=0.002`, + 'cache-control': `max-age=0.005`, 'last-modified': 'Mon, 11 Dec 2023 01:00:00 GMT' }); @@ -2292,7 +2292,7 @@ describe('SyncFetch', () => { expect(headers2).toEqual({ 'content-type': 'text/html', 'content-length': String(responseText.length), - 'Cache-Control': 'max-age=0.002', + 'Cache-Control': 'max-age=0.005', 'Last-Modified': 'Mon, 11 Dec 2023 02:00:00 GMT' }); @@ -2329,7 +2329,7 @@ describe('SyncFetch', () => { ]); }); - it('Updates cache after a failed revalidation with a "If-Modified-Since" request for a GET response with "Cache-Control" set to "max-age=0.002".', async () => { + it('Updates cache after a failed revalidation with a "If-Modified-Since" request for a GET response with "Cache-Control" set to "max-age=0.005".', async () => { browserFrame.url = 'https://localhost:8080/'; const url = 'https://localhost:8080/some/path'; @@ -2353,7 +2353,7 @@ describe('SyncFetch', () => { 'content-length', String(responseText2.length), 'cache-control', - 'max-age=0.002', + 'max-age=0.005', 'last-modified', 'Mon, 11 Dec 2023 02:00:00 GMT' ], @@ -2372,7 +2372,7 @@ describe('SyncFetch', () => { 'content-length', String(responseText1.length), 'cache-control', - 'max-age=0.002', + 'max-age=0.005', 'last-modified', 'Mon, 11 Dec 2023 01:00:00 GMT' ], @@ -2426,7 +2426,7 @@ describe('SyncFetch', () => { expect(headers1).toEqual({ 'content-type': 'text/html', 'content-length': String(responseText1.length), - 'cache-control': `max-age=0.002`, + 'cache-control': `max-age=0.005`, 'last-modified': 'Mon, 11 Dec 2023 01:00:00 GMT' }); @@ -2439,7 +2439,7 @@ describe('SyncFetch', () => { expect(headers2).toEqual({ 'content-type': 'text/html', 'content-length': String(responseText2.length), - 'cache-control': 'max-age=0.002', + 'cache-control': 'max-age=0.005', 'last-modified': 'Mon, 11 Dec 2023 02:00:00 GMT' }); @@ -2519,7 +2519,7 @@ describe('SyncFetch', () => { 'content-length', String(responseText.length), 'cache-control', - 'max-age=0.002', + 'max-age=0.005', 'last-modified', 'Mon, 11 Dec 2023 01:00:00 GMT', 'etag', @@ -2575,7 +2575,7 @@ describe('SyncFetch', () => { expect(headers1).toEqual({ 'content-type': 'text/html', 'content-length': String(responseText.length), - 'cache-control': `max-age=0.002`, + 'cache-control': `max-age=0.005`, 'last-modified': 'Mon, 11 Dec 2023 01:00:00 GMT', etag: etag1 }); @@ -2589,7 +2589,7 @@ describe('SyncFetch', () => { expect(headers2).toEqual({ 'content-type': 'text/html', 'content-length': String(responseText.length), - 'cache-control': `max-age=0.002`, + 'cache-control': `max-age=0.005`, 'Last-Modified': 'Mon, 11 Dec 2023 02:00:00 GMT', ETag: etag2 }); @@ -2653,7 +2653,7 @@ describe('SyncFetch', () => { 'content-length', String(responseText2.length), 'cache-control', - 'max-age=0.002', + 'max-age=0.005', 'last-modified', 'Mon, 11 Dec 2023 02:00:00 GMT', 'etag', @@ -2674,7 +2674,7 @@ describe('SyncFetch', () => { 'content-length', String(responseText1.length), 'cache-control', - 'max-age=0.002', + 'max-age=0.005', 'last-modified', 'Mon, 11 Dec 2023 01:00:00 GMT', 'etag', @@ -2722,7 +2722,7 @@ describe('SyncFetch', () => { expect(headers1).toEqual({ 'content-type': 'text/html', 'content-length': String(responseText1.length), - 'cache-control': `max-age=0.002`, + 'cache-control': `max-age=0.005`, 'last-modified': 'Mon, 11 Dec 2023 01:00:00 GMT', etag: etag1 }); @@ -2736,7 +2736,7 @@ describe('SyncFetch', () => { expect(headers2).toEqual({ 'content-type': 'text/html', 'content-length': String(responseText2.length), - 'cache-control': `max-age=0.002`, + 'cache-control': `max-age=0.005`, 'last-modified': 'Mon, 11 Dec 2023 02:00:00 GMT', etag: etag2 }); diff --git a/packages/happy-dom/test/nodes/document/Document.test.ts b/packages/happy-dom/test/nodes/document/Document.test.ts index 52d7b1d6f..fb44b19f3 100644 --- a/packages/happy-dom/test/nodes/document/Document.test.ts +++ b/packages/happy-dom/test/nodes/document/Document.test.ts @@ -1088,12 +1088,35 @@ describe('Document', () => { describe('importNode()', () => { it('Creates a clone of a Node and sets the ownerDocument to be the current document.', () => { - const node = new Window().document.createElement('div'); - const clone = document.importNode(node); + const window1 = new Window(); + const window2 = new Window(); + const node = window1.document.createElement('div'); + const clone = window2.document.importNode(node); expect(clone.tagName).toBe('DIV'); - expect(clone.ownerDocument === document).toBe(true); + expect(clone.ownerDocument === window2.document).toBe(true); expect(clone instanceof HTMLElement).toBe(true); }); + + it('Creates a clone of a Node and sets the ownerDocument to be the current document on child nodes when setting the "deep" parameter to "true".', () => { + const window1 = new Window(); + const window2 = new Window(); + const node = window1.document.createElement('div'); + const childNode1 = window1.document.createElement('span'); + const childNode2 = window1.document.createElement('span'); + + node.appendChild(childNode1); + node.appendChild(childNode2); + + const clone = window2.document.importNode(node, true); + expect(clone.tagName).toBe('DIV'); + expect(clone.ownerDocument === window2.document).toBe(true); + + expect(clone.children.length).toBe(2); + expect(clone.children[0].tagName).toBe('SPAN'); + expect(clone.children[0].ownerDocument === window2.document).toBe(true); + expect(clone.children[1].tagName).toBe('SPAN'); + expect(clone.children[1].ownerDocument === window2.document).toBe(true); + }); }); describe('cloneNode()', () => {