diff --git a/packages/happy-dom/src/nodes/document/Document.ts b/packages/happy-dom/src/nodes/document/Document.ts index b5afb670..7092f9bb 100644 --- a/packages/happy-dom/src/nodes/document/Document.ts +++ b/packages/happy-dom/src/nodes/document/Document.ts @@ -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)); } /** @@ -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)); } /** @@ -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); } /** @@ -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; @@ -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; diff --git a/packages/happy-dom/test/nodes/document/Document.test.ts b/packages/happy-dom/test/nodes/document/Document.test.ts index 3de45d60..a5a5c330 100644 --- a/packages/happy-dom/test/nodes/document/Document.test.ts +++ b/packages/happy-dom/test/nodes/document/Document.test.ts @@ -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'); @@ -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.', () => { @@ -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.', () => { @@ -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); }); }); @@ -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);