nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: capricorn86/happy-dom
Pull request #332 (2022-01-18 00:56:10)

#328@minor: Add toggle() to ClassList.
Fixes https://github.com/capricorn86/happy-dom/issues/328

Implements `toggle()` on `ClassList` (see https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/toggle)


![image](https://user-images.githubusercontent.com/22725671/149852755-6f0f51d3-ea54-42ce-bf70-a2f4247d7f77.png)



Patch:
diff --git a/packages/happy-dom/src/nodes/element/ClassList.ts b/packages/happy-dom/src/nodes/element/ClassList.ts
index 976c3442..56a0bea3 100644
--- a/packages/happy-dom/src/nodes/element/ClassList.ts
+++ b/packages/happy-dom/src/nodes/element/ClassList.ts
@@ -65,4 +65,28 @@ export default class ClassList {
 		const list = attr ? attr.split(' ') : [];
 		return list.includes(className);
 	}
+
+	/**
+	 * Toggle a class name.
+	 *
+	 * @param className A string representing the class name you want to toggle.
+	 * @param force If included, turns the toggle into a one way-only operation. If set to `false`, then class name will only be removed, but not added. If set to `true`, then class name will only be added, but not removed.
+	 * @returns A boolean value, `true` or `false`, indicating whether class name is in the list after the call or not.
+	 */
+	public toggle(className: string, force?: boolean): boolean {
+		let shouldAdd: boolean;
+		if (force !== undefined) {
+			shouldAdd = force;
+		} else {
+			shouldAdd = !this.contains(className);
+		}
+
+		if (shouldAdd) {
+			this.add(className);
+			return true;
+		}
+
+		this.remove(className);
+		return false;
+	}
 }


Test patch:
diff --git a/packages/happy-dom/test/nodes/element/ClassList.test.ts b/packages/happy-dom/test/nodes/element/ClassList.test.ts
index eccf8010..b820ff72 100644
--- a/packages/happy-dom/test/nodes/element/ClassList.test.ts
+++ b/packages/happy-dom/test/nodes/element/ClassList.test.ts
@@ -43,4 +43,28 @@ describe('ClassList', () => {
 			expect(classList.contains('class')).toBe(true);
 		});
 	});
+
+	describe('toggle()', () => {
+		it('Adds a class from the list when not existing.', () => {
+			expect(classList.toggle('class')).toBe(true);
+			expect(element.className).toBe('class');
+		});
+		it('Adds a class from the list when force is set.', () => {
+			classList.add('classA');
+			expect(classList.toggle('classA', true)).toBe(true);
+			expect(classList.toggle('classB', true)).toBe(true);
+			expect(element.className).toBe('classA classB');
+		});
+		it('Removes a class from the list when existing.', () => {
+			classList.add('class');
+			expect(classList.toggle('class')).toBe(false);
+			expect(element.className).toBe('');
+		});
+		it('Adds a class from the list when force is set.', () => {
+			classList.add('classA');
+			expect(classList.toggle('classA', false)).toBe(false);
+			expect(classList.toggle('classB', false)).toBe(false);
+			expect(element.className).toBe('');
+		});
+	});
 });
Repository: capricorn86/happy-dom
Pull request #340 (2022-01-25 00:11:19)

#338@minor: Adds support for the deprecated method CustomEvent.initCu…
…stomEvent() which is used by Svelte.


Patch:
diff --git a/packages/happy-dom/src/event/events/CustomEvent.ts b/packages/happy-dom/src/event/events/CustomEvent.ts
index 70b22598..86eb8a9c 100644
--- a/packages/happy-dom/src/event/events/CustomEvent.ts
+++ b/packages/happy-dom/src/event/events/CustomEvent.ts
@@ -20,4 +20,25 @@ export default class CustomEvent extends Event {
 			this.detail = eventInit.detail || null;
 		}
 	}
+
+	/**
+	 * Init event.
+	 *
+	 * @deprecated
+	 * @param type Type.
+	 * @param [bubbles=false] "true" if it bubbles.
+	 * @param [cancelable=false] "true" if it cancelable.
+	 * @param [detail=null] Custom event detail.
+	 */
+	public initCustomEvent(
+		type: string,
+		bubbles = false,
+		cancelable = false,
+		detail: object = null
+	): void {
+		this.type = type;
+		this.bubbles = bubbles;
+		this.cancelable = cancelable;
+		this.detail = detail;
+	}
 }
diff --git a/packages/happy-dom/src/nodes/document/Document.ts b/packages/happy-dom/src/nodes/document/Document.ts
index dc543503..3f6c66b1 100644
--- a/packages/happy-dom/src/nodes/document/Document.ts
+++ b/packages/happy-dom/src/nodes/document/Document.ts
@@ -620,10 +620,13 @@ export default class Document extends Node implements IDocument {
 	 * Creates an event.
 	 *
 	 * @deprecated
-	 * @param _type Type.
+	 * @param type Type.
 	 * @returns Event.
 	 */
-	public createEvent(_type: string): Event {
+	public createEvent(type: string): Event {
+		if (this.defaultView[type]) {
+			return new this.defaultView[type]('init');
+		}
 		return new Event('init');
 	}
 


Test patch:
diff --git a/packages/happy-dom/test/nodes/document/Document.test.ts b/packages/happy-dom/test/nodes/document/Document.test.ts
index a05a834a..34874009 100644
--- a/packages/happy-dom/test/nodes/document/Document.test.ts
+++ b/packages/happy-dom/test/nodes/document/Document.test.ts
@@ -25,7 +25,8 @@ import IResponse from '../../../src/window/IResponse';
 import ResourceFetcher from '../../../src/fetch/ResourceFetcher';
 import IHTMLScriptElement from '../../../src/nodes/html-script-element/IHTMLScriptElement';
 import DocumentReadyStateEnum from '../../../src/nodes/document/DocumentReadyStateEnum';
-import { ISVGElement } from '../../../src';
+import ISVGElement from '../../../src/nodes/svg-element/ISVGElement';
+import CustomEvent from '../../../src/event/events/CustomEvent';
 
 describe('Document', () => {
 	let window: Window;
@@ -794,6 +795,17 @@ describe('Document', () => {
 			expect(event.cancelable).toBe(true);
 			expect(event instanceof Event).toBe(true);
 		});
+
+		it('Creates a legacy custom event.', () => {
+			const event = <CustomEvent>document.createEvent('CustomEvent');
+			const detail = {};
+			event.initCustomEvent('click', true, true, detail);
+			expect(event.type).toBe('click');
+			expect(event.bubbles).toBe(true);
+			expect(event.cancelable).toBe(true);
+			expect(event.detail).toBe(detail);
+			expect(event instanceof CustomEvent).toBe(true);
+		});
 	});
 
 	describe('importNode()', () => {
Repository: capricorn86/happy-dom
Pull request #360 (2022-02-16 15:31:37)

#342@patch: When an input element is appended to a label as a child, …
…HTMLLabelElement.control should return it.


Patch:
diff --git a/packages/happy-dom/src/nodes/html-label-element/HTMLLabelElement.ts b/packages/happy-dom/src/nodes/html-label-element/HTMLLabelElement.ts
index 988a5aae..a4a62fc4 100644
--- a/packages/happy-dom/src/nodes/html-label-element/HTMLLabelElement.ts
+++ b/packages/happy-dom/src/nodes/html-label-element/HTMLLabelElement.ts
@@ -41,7 +41,15 @@ export default class HTMLLabelElement extends HTMLElement implements IHTMLLabelE
 	 */
 	public get control(): IHTMLElement {
 		const htmlFor = this.htmlFor;
-		return htmlFor ? <IHTMLElement>this.ownerDocument.getElementById(htmlFor) : null;
+		if (htmlFor) {
+			return <IHTMLElement>this.ownerDocument.getElementById(htmlFor);
+		}
+		for (const child of this.children) {
+			if (child.tagName === 'INPUT') {
+				return <IHTMLElement>child;
+			}
+		}
+		return null;
 	}
 
 	/**


Test patch:
diff --git a/packages/happy-dom/test/nodes/html-label-element/HTMLLabelElement.test.ts b/packages/happy-dom/test/nodes/html-label-element/HTMLLabelElement.test.ts
index 286e936d..9f1d2e24 100644
--- a/packages/happy-dom/test/nodes/html-label-element/HTMLLabelElement.test.ts
+++ b/packages/happy-dom/test/nodes/html-label-element/HTMLLabelElement.test.ts
@@ -29,7 +29,7 @@ describe('HTMLLabelElement', () => {
 	});
 
 	describe('get control()', () => {
-		it('Returns element controlling the label.', () => {
+		it('Returns element controlling the label when "for" attribute has been defined.', () => {
 			const input = document.createElement('input');
 			input.id = 'inputId';
 			element.htmlFor = 'inputId';
@@ -37,6 +37,12 @@ describe('HTMLLabelElement', () => {
 			document.appendChild(element);
 			expect(element.control === input).toBe(true);
 		});
+
+		it('Returns input appended as a child if "for" attribute is not defined.', () => {
+			const input = document.createElement('input');
+			element.appendChild(input);
+			expect(element.control === input).toBe(true);
+		});
 	});
 
 	describe('get form()', () => {
Repository: capricorn86/happy-dom
Pull request #362 (2022-02-17 15:16:55)

#350@minor: Adds support for Document.scrollingElement.


Patch:
diff --git a/packages/happy-dom/src/nodes/document/Document.ts b/packages/happy-dom/src/nodes/document/Document.ts
index ec8c72e4..bc58d803 100644
--- a/packages/happy-dom/src/nodes/document/Document.ts
+++ b/packages/happy-dom/src/nodes/document/Document.ts
@@ -221,6 +221,15 @@ export default class Document extends Node implements IDocument {
 		return this._activeElement || this.body || this.documentElement || null;
 	}
 
+	/**
+	 * Returns scrolling element.
+	 *
+	 * @returns Scrolling element.
+	 */
+	public get scrollingElement(): IHTMLElement {
+		return this.documentElement;
+	}
+
 	/**
 	 * Returns location.
 	 *


Test patch:
diff --git a/packages/happy-dom/test/nodes/document/Document.test.ts b/packages/happy-dom/test/nodes/document/Document.test.ts
index da85a1b3..33dcc098 100644
--- a/packages/happy-dom/test/nodes/document/Document.test.ts
+++ b/packages/happy-dom/test/nodes/document/Document.test.ts
@@ -275,6 +275,12 @@ describe('Document', () => {
 		});
 	});
 
+	describe('get scrollingElement()', () => {
+		it('Returns document element as scrolling element.', () => {
+			expect(document.scrollingElement === document.documentElement).toBe(true);
+		});
+	});
+
 	describe('get location()', () => {
 		it('Returns the current location', () => {
 			expect(document.location === window.location).toBe(true);
Repository: capricorn86/happy-dom
Pull request #363 (2022-02-17 15:45:29)

#348@minor: Adds support for Node.contains().


Patch:
diff --git a/packages/happy-dom/src/nodes/node/INode.ts b/packages/happy-dom/src/nodes/node/INode.ts
index 9bfaa3c9..04d9eadb 100644
--- a/packages/happy-dom/src/nodes/node/INode.ts
+++ b/packages/happy-dom/src/nodes/node/INode.ts
@@ -24,6 +24,7 @@ export default interface INode extends IEventTarget {
 	appendChild(node: INode): INode;
 	removeChild(node: INode): INode;
 	hasChildNodes(): boolean;
+	contains(otherNode: INode): boolean;
 	insertBefore(newNode: INode, referenceNode?: INode | null): INode;
 	replaceChild(newChild: INode, oldChild: INode): INode;
 	toString(): string;
diff --git a/packages/happy-dom/src/nodes/node/Node.ts b/packages/happy-dom/src/nodes/node/Node.ts
index ec7709e7..3d54ab8a 100644
--- a/packages/happy-dom/src/nodes/node/Node.ts
+++ b/packages/happy-dom/src/nodes/node/Node.ts
@@ -169,6 +169,21 @@ export default class Node extends EventTarget implements INode {
 		return this.childNodes.length > 0;
 	}
 
+	/**
+	 * Returns "true" if this node contains the other node.
+	 *
+	 * @param otherNode Node to test with.
+	 * @returns "true" if this node contains the other node.
+	 */
+	public contains(otherNode: INode): boolean {
+		for (const childNode of this.childNodes) {
+			if (childNode === otherNode || childNode.contains(otherNode)) {
+				return true;
+			}
+		}
+		return false;
+	}
+
 	/**
 	 * Returns closest root node (Document or ShadowRoot).
 	 *


Test patch:
diff --git a/packages/happy-dom/test/nodes/node/Node.test.ts b/packages/happy-dom/test/nodes/node/Node.test.ts
index 4c741641..49bcaec5 100644
--- a/packages/happy-dom/test/nodes/node/Node.test.ts
+++ b/packages/happy-dom/test/nodes/node/Node.test.ts
@@ -236,6 +236,37 @@ describe('Node', () => {
 		});
 	});
 
+	describe('hasChildNodes()', () => {
+		it('Returns "true" if the Node has child nodes.', () => {
+			const parent = document.createElement('div');
+			const child = document.createElement('span');
+
+			expect(parent.hasChildNodes()).toBe(false);
+
+			parent.appendChild(child);
+
+			expect(parent.hasChildNodes()).toBe(true);
+		});
+	});
+
+	describe('contains()', () => {
+		it('Returns "true" if a node contains another node.', () => {
+			const div = document.createElement('div');
+			const span1 = document.createElement('span');
+			const span2 = document.createElement('span');
+			const text = document.createTextNode('text');
+
+			div.appendChild(span1);
+			div.appendChild(span2);
+
+			expect(div.contains(text)).toBe(false);
+
+			span2.appendChild(text);
+
+			expect(div.contains(text)).toBe(true);
+		});
+	});
+
 	describe('getRootNode()', () => {
 		it('Returns ShadowRoot when used on a node inside a ShadowRoot.', () => {
 			const customElement = document.createElement('custom-counter');
Repository: capricorn86/happy-dom
Pull request #364 (2022-02-17 16:05:17)

#351@minor: Adds support for Window.performance.


Patch:
diff --git a/packages/happy-dom/src/window/Window.ts b/packages/happy-dom/src/window/Window.ts
index 0788eac4..a5f22247 100644
--- a/packages/happy-dom/src/window/Window.ts
+++ b/packages/happy-dom/src/window/Window.ts
@@ -70,6 +70,7 @@ import URLSearchParams from '../url-search-params/URLSearchParams';
 import HTMLCollection from '../nodes/element/HTMLCollection';
 import NodeList from '../nodes/node/NodeList';
 import MediaQueryList from '../match-media/MediaQueryList';
+import * as PerfHooks from 'perf_hooks';
 
 const FETCH_RESPONSE_TYPE_METHODS = ['blob', 'json', 'text'];
 
@@ -176,6 +177,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
 	public readonly devicePixelRatio = 1;
 	public readonly sessionStorage = new Storage();
 	public readonly localStorage = new Storage();
+	public readonly performance = PerfHooks.performance;
 
 	// Node.js Globals
 	public Array = global ? global.Array : null;


Test patch:
diff --git a/packages/happy-dom/test/window/Window.test.ts b/packages/happy-dom/test/window/Window.test.ts
index dba721f6..99aaed98 100644
--- a/packages/happy-dom/test/window/Window.test.ts
+++ b/packages/happy-dom/test/window/Window.test.ts
@@ -42,6 +42,12 @@ describe('Window', () => {
 		jest.restoreAllMocks();
 	});
 
+	describe('get performance()', () => {
+		it('Exposes "performance" from the NodeJS perf_hooks package.', () => {
+			expect(typeof window.performance.now()).toBe('number');
+		});
+	});
+
 	describe('getComputedStyle()', () => {
 		it('Returns a CSSStyleDeclaration object with computed styles that are live updated whenever the element styles are changed.', () => {
 			const element = <HTMLElement>window.document.createElement('div');
Repository: capricorn86/happy-dom
Pull request #392 (2022-03-07 14:50:40)

#382@minor: Adds support for Document.hasFocus().


Patch:
diff --git a/packages/happy-dom/src/nodes/document/Document.ts b/packages/happy-dom/src/nodes/document/Document.ts
index 676b44f6..a857c1e7 100644
--- a/packages/happy-dom/src/nodes/document/Document.ts
+++ b/packages/happy-dom/src/nodes/document/Document.ts
@@ -719,6 +719,15 @@ export default class Document extends Node implements IDocument {
 		return new Selection();
 	}
 
+	/**
+	 * Returns a boolean value indicating whether the document or any element inside the document has focus.
+	 *
+	 * @returns "true" if the document has focus.
+	 */
+	public hasFocus(): boolean {
+		return !!this.activeElement;
+	}
+
 	/**
 	 * @override
 	 */
diff --git a/packages/happy-dom/src/nodes/document/IDocument.ts b/packages/happy-dom/src/nodes/document/IDocument.ts
index 08f4facb..371792bc 100644
--- a/packages/happy-dom/src/nodes/document/IDocument.ts
+++ b/packages/happy-dom/src/nodes/document/IDocument.ts
@@ -171,4 +171,11 @@ export default interface IDocument extends IParentNode {
 	 * @returns Selection.
 	 */
 	getSelection(): Selection;
+
+	/**
+	 * Returns a boolean value indicating whether the document or any element inside the document has focus.
+	 *
+	 * @returns "true" if the document has focus.
+	 */
+	hasFocus(): boolean;
 }


Test patch:
diff --git a/packages/happy-dom/test/nodes/document/Document.test.ts b/packages/happy-dom/test/nodes/document/Document.test.ts
index 7dd257df..dcf8ae1f 100644
--- a/packages/happy-dom/test/nodes/document/Document.test.ts
+++ b/packages/happy-dom/test/nodes/document/Document.test.ts
@@ -967,6 +967,14 @@ describe('Document', () => {
 		});
 	});
 
+	describe('hasFocus()', () => {
+		it('Returns "true" if activeElement has focus.', () => {
+			expect(document.hasFocus()).toBe(true);
+			document.documentElement.remove();
+			expect(document.hasFocus()).toBe(false);
+		});
+	});
+
 	describe('dispatchEvent()', () => {
 		it('Bubbles events to Window.', () => {
 			const event = new Event('click', { bubbles: true });
Repository: capricorn86/happy-dom
Pull request #399 (2022-03-10 12:47:48)

#396@patch: Bugfix for Window.eval() not returning its result.


Patch:
diff --git a/packages/happy-dom/src/window/IWindow.ts b/packages/happy-dom/src/window/IWindow.ts
index a3d61b4c..89a63f64 100644
--- a/packages/happy-dom/src/window/IWindow.ts
+++ b/packages/happy-dom/src/window/IWindow.ts
@@ -188,8 +188,9 @@ export default interface IWindow extends IEventTarget {
 	 * Evaluates code.
 	 *
 	 * @param code Code.
+	 * @returns Result.
 	 */
-	eval(code: string): void;
+	eval(code: string): unknown;
 
 	/**
 	 * Returns an object containing the values of all CSS properties of an element.
diff --git a/packages/happy-dom/src/window/Window.ts b/packages/happy-dom/src/window/Window.ts
index 542ff311..59b96cf3 100644
--- a/packages/happy-dom/src/window/Window.ts
+++ b/packages/happy-dom/src/window/Window.ts
@@ -309,8 +309,9 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
 	 * Evaluates code.
 	 *
 	 * @param code Code.
+	 * @returns Result.
 	 */
-	public eval(code: string): void {
+	public eval(code: string): unknown {
 		let vmExists = false;
 		let vm = null;
 
@@ -325,10 +326,10 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
 		}
 
 		if (global && vm && vm.isContext(this)) {
-			vm.runInContext(code, this);
-		} else if (global && global.eval) {
-			global.eval(code);
+			return vm.runInContext(code, this);
 		}
+
+		return global.eval(code);
 	}
 
 	/**


Test patch:
diff --git a/packages/happy-dom/test/window/Window.test.ts b/packages/happy-dom/test/window/Window.test.ts
index 6b6810c7..3f8ae75e 100644
--- a/packages/happy-dom/test/window/Window.test.ts
+++ b/packages/happy-dom/test/window/Window.test.ts
@@ -101,6 +101,13 @@ describe('Window', () => {
 		});
 	});
 
+	describe('eval()', () => {
+		it('Evaluates code and returns the result.', () => {
+			const result = <() => number>window.eval('() => 5');
+			expect(result()).toBe(5);
+		});
+	});
+
 	describe('setTimeout()', () => {
 		it('Sets a timeout.', done => {
 			const timeoutId = window.setTimeout(() => done());
Repository: capricorn86/happy-dom
Pull request #423 (2022-03-21 13:01:36)

#349@patch: Fixes issue with Element.innerHTML not parsing unclosed r…
…egular elements (like <div>) correctly.


Patch:
diff --git a/packages/happy-dom/src/xml-parser/XMLParser.ts b/packages/happy-dom/src/xml-parser/XMLParser.ts
index aeebf8db..1487360c 100755
--- a/packages/happy-dom/src/xml-parser/XMLParser.ts
+++ b/packages/happy-dom/src/xml-parser/XMLParser.ts
@@ -112,7 +112,7 @@ export default class XMLParser {
 		// Text after last element
 		if ((!match && data.length > 0) || (match && lastTextIndex !== match.index)) {
 			const text = data.substring(lastTextIndex);
-			this.appendTextAndCommentNodes(document, root, text);
+			this.appendTextAndCommentNodes(document, parent || root, text);
 		}
 
 		return root;


Test patch:
diff --git a/packages/happy-dom/test/xml-parser/XMLParser.test.ts b/packages/happy-dom/test/xml-parser/XMLParser.test.ts
index d2761307..d23dcf4c 100644
--- a/packages/happy-dom/test/xml-parser/XMLParser.test.ts
+++ b/packages/happy-dom/test/xml-parser/XMLParser.test.ts
@@ -1,6 +1,8 @@
 import XMLParser from '../../src/xml-parser/XMLParser';
 import Window from '../../src/window/Window';
-import Document from '../../src/nodes/document/Document';
+import IWindow from '../../src/window/IWindow';
+import IDocument from '../../src/nodes/document/IDocument';
+import Node from '../../src/nodes/node/Node';
 import IHTMLElement from '../../src/nodes/html-element/IHTMLElement';
 import IHTMLTemplateElement from '../../src/nodes/html-template-element/IHTMLTemplateElement';
 import XMLParserHTML from './data/XMLParserHTML';
@@ -16,8 +18,8 @@ const GET_EXPECTED_HTML = (html: string): string =>
 		.replace(/[\s]/gm, '');
 
 describe('XMLParser', () => {
-	let window: Window;
-	let document: Document;
+	let window: IWindow;
+	let document: IDocument;
 
 	beforeEach(() => {
 		window = new Window();
@@ -186,6 +188,14 @@ describe('XMLParser', () => {
 			);
 		});
 
+		it('Handles unclosed regular elements.', () => {
+			const root = XMLParser.parse(window.document, `<div>test`);
+
+			expect(root.childNodes.length).toBe(1);
+			expect((<IHTMLElement>root.childNodes[0]).tagName).toBe('DIV');
+			expect(root.childNodes[0].childNodes[0].nodeType).toBe(Node.TEXT_NODE);
+		});
+
 		it('Parses an SVG with "xmlns" set to HTML.', () => {
 			const root = XMLParser.parse(
 				window.document,
Repository: capricorn86/happy-dom
Pull request #441 (2022-03-31 14:48:28)

#405@patch: Adds support for sending in other values than strings as …
…tag name to Document.createElement() and Document.createElementNS().


Patch:
diff --git a/packages/happy-dom/src/nodes/document/Document.ts b/packages/happy-dom/src/nodes/document/Document.ts
index 922818a5..5717007a 100644
--- a/packages/happy-dom/src/nodes/document/Document.ts
+++ b/packages/happy-dom/src/nodes/document/Document.ts
@@ -630,11 +630,11 @@ export default class Document extends Node implements IDocument {
 		qualifiedName: string,
 		options?: { is?: string }
 	): IElement {
-		const tagName = qualifiedName.toUpperCase();
+		const tagName = String(qualifiedName).toUpperCase();
 
 		let customElementClass;
 		if (this.defaultView && options && options.is) {
-			customElementClass = this.defaultView.customElements.get(options.is);
+			customElementClass = this.defaultView.customElements.get(String(options.is));
 		} else if (this.defaultView) {
 			customElementClass = this.defaultView.customElements.get(tagName);
 		}


Test patch:
diff --git a/packages/happy-dom/test/nodes/document/Document.test.ts b/packages/happy-dom/test/nodes/document/Document.test.ts
index e513d303..10665b3e 100644
--- a/packages/happy-dom/test/nodes/document/Document.test.ts
+++ b/packages/happy-dom/test/nodes/document/Document.test.ts
@@ -793,6 +793,11 @@ describe('Document', () => {
 			svg.style.cssText = 'user-select:none;';
 			expect(svg.style.cssText).toBe('user-select: none;');
 		});
+
+		it("Creates an element when tag name isn't a string.", () => {
+			const element = <ISVGElement>document.createElementNS(null, <string>(<unknown>true));
+			expect(element.tagName).toBe('TRUE');
+		});
 	});
 
 	describe('createAttribute()', () => {