Skip to content

Commit

Permalink
#466@trivial: Adds unit test for importNode().
Browse files Browse the repository at this point in the history
  • Loading branch information
capricorn86 committed Jan 10, 2024
1 parent c6ca530 commit 32e144e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 20 deletions.
34 changes: 17 additions & 17 deletions packages/happy-dom/test/fetch/SyncFetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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: ''
}
Expand All @@ -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'
],
Expand Down Expand Up @@ -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'
});

Expand All @@ -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'
});

Expand Down Expand Up @@ -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';
Expand All @@ -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'
],
Expand All @@ -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'
],
Expand Down Expand Up @@ -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'
});

Expand All @@ -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'
});

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
});
Expand All @@ -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
});
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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
});
Expand All @@ -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
});
Expand Down
29 changes: 26 additions & 3 deletions packages/happy-dom/test/nodes/document/Document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <Element>document.importNode(node);
const window1 = new Window();
const window2 = new Window();
const node = window1.document.createElement('div');
const clone = <Element>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 = <Element>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()', () => {
Expand Down

0 comments on commit 32e144e

Please sign in to comment.