Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [#1577] Fixes issue where Comment, Text and DocumentFragment is not an instance of their corresponding property on Window #1675

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/happy-dom/src/nodes/document/Document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ export default class Document extends Node {
);
}
// We should use the NodeFactory and not the class constructor, so that owner document will be this document
return NodeFactory.createNode(this, Text, String(data));
return NodeFactory.createNode(this, this[PropertySymbol.window].Text, String(data));
}

/**
Expand All @@ -1164,7 +1164,7 @@ export default class Document extends Node {
);
}
// We should use the NodeFactory and not the class constructor, so that owner document will be this document
return NodeFactory.createNode(this, Comment, String(data));
return NodeFactory.createNode(this, this[PropertySymbol.window].Comment, String(data));
}

/**
Expand All @@ -1174,7 +1174,7 @@ export default class Document extends Node {
*/
public createDocumentFragment(): DocumentFragment {
// We should use the NodeFactory and not the class constructor, so that owner document will be this document
return NodeFactory.createNode(this, DocumentFragment);
return NodeFactory.createNode(this, this[PropertySymbol.window].DocumentFragment);
}

/**
Expand Down Expand Up @@ -1232,7 +1232,7 @@ export default class Document extends Node {
*/
public createAttributeNS(namespaceURI: string, qualifiedName: string): Attr {
// We should use the NodeFactory and not the class constructor, so that owner document will be this document
const attribute = NodeFactory.createNode(this, Attr);
const attribute = NodeFactory.createNode(this, this[PropertySymbol.window].Attr);

const parts = qualifiedName.split(':');
attribute[PropertySymbol.namespaceURI] = namespaceURI;
Expand Down Expand Up @@ -1335,7 +1335,7 @@ export default class Document extends Node {
);
}
// We should use the NodeFactory and not the class constructor, so that owner document will be this document
const element = NodeFactory.createNode(this, ProcessingInstruction);
const element = NodeFactory.createNode(this, this[PropertySymbol.window].ProcessingInstruction);

element[PropertySymbol.data] = data;
element[PropertySymbol.target] = target;
Expand Down
12 changes: 6 additions & 6 deletions packages/happy-dom/test/nodes/document/Document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ describe('Document', () => {
it('Creates an Attr node.', () => {
const attribute = document.createAttribute('KEY1');

expect(attribute instanceof Attr).toBe(true);
expect(attribute instanceof window.Attr).toBe(true);

expect(attribute.value).toBe(null);
expect(attribute.name).toBe('key1');
Expand Down Expand Up @@ -1179,7 +1179,7 @@ describe('Document', () => {
const textContent = 'text';
const textNode = document.createTextNode(textContent);
expect(textNode.textContent).toBe(textContent);
expect(textNode instanceof Text).toBe(true);
expect(textNode instanceof window.Text).toBe(true);
});

it('Creates a text node without content.', () => {
Expand All @@ -1206,9 +1206,9 @@ describe('Document', () => {
describe('createComment()', () => {
it('Creates a comment node.', () => {
const commentContent = 'comment';
const commentNode = document.createTextNode(commentContent);
const commentNode = document.createComment(commentContent);
expect(commentNode.textContent).toBe(commentContent);
expect(commentNode instanceof Text).toBe(true);
expect(commentNode instanceof window.Comment).toBe(true);
});

it('Creates a comment node without content.', () => {
Expand Down Expand Up @@ -1236,7 +1236,7 @@ describe('Document', () => {
it('Creates a document fragment.', () => {
const documentFragment = document.createDocumentFragment();
expect(documentFragment.ownerDocument).toBe(document);
expect(documentFragment instanceof DocumentFragment).toBe(true);
expect(documentFragment instanceof window.DocumentFragment).toBe(true);
});
});

Expand Down Expand Up @@ -1524,7 +1524,7 @@ describe('Document', () => {
describe('createProcessingInstruction()', () => {
it('Creates a Processing Instruction node with target & data.', () => {
const instruction = document.createProcessingInstruction('foo', 'bar');
expect(instruction instanceof ProcessingInstruction).toBe(true);
expect(instruction instanceof window.ProcessingInstruction).toBe(true);
expect(instruction.target).toBe('foo');
expect(instruction.data).toBe('bar');
expect(instruction.ownerDocument).toBe(document);
Expand Down
Loading