Repository: capricorn86/happy-dom (ts)

Issue:
No type checking in various unit tests
**Describe the bug**
There are various unit tests that declare "windows" or "document" without type. This makes them type "any" which completly lacks any type checking (pun intended).

**To Reproduce**
[Node.test.ts](https://github.com/capricorn86/happy-dom/blob/master/packages/happy-dom/test/nodes/node/Node.test.ts#L58)

**Additional context**
I will prepare a MR.


Pull request:
#860@patch: Improve type checking in unit tests
fix #860

- Add types to `let document;` and `let window;` in unit tests
- `Window.ts`: simplified default imports

New bug fixes found by type checker:
- Fix: `cloneNode` parameter is optional (all Node related interfaces)
- Fix: missing `IShadowRoot.activeElement`

Patch:
diff --git a/packages/happy-dom/src/nodes/document-fragment/IDocumentFragment.ts b/packages/happy-dom/src/nodes/document-fragment/IDocumentFragment.ts
index 26dfce10..bac3d0bc 100644
--- a/packages/happy-dom/src/nodes/document-fragment/IDocumentFragment.ts
+++ b/packages/happy-dom/src/nodes/document-fragment/IDocumentFragment.ts
@@ -60,5 +60,5 @@ export default interface IDocumentFragment extends INode {
 	 * @param [deep=false] "true" to clone deep.
 	 * @returns Cloned node.
 	 */
-	cloneNode(deep: boolean): IDocumentFragment;
+	cloneNode(deep?: boolean): IDocumentFragment;
 }
diff --git a/packages/happy-dom/src/nodes/document-type/IDocumentType.ts b/packages/happy-dom/src/nodes/document-type/IDocumentType.ts
index fe1102cf..d37493c3 100644
--- a/packages/happy-dom/src/nodes/document-type/IDocumentType.ts
+++ b/packages/happy-dom/src/nodes/document-type/IDocumentType.ts
@@ -15,5 +15,5 @@ export default interface IDocumentType extends INode {
 	 * @param [deep=false] "true" to clone deep.
 	 * @returns Cloned node.
 	 */
-	cloneNode(deep: boolean): IDocumentType;
+	cloneNode(deep?: boolean): IDocumentType;
 }
diff --git a/packages/happy-dom/src/nodes/document/IDocument.ts b/packages/happy-dom/src/nodes/document/IDocument.ts
index 0b627a3f..8dc3475e 100644
--- a/packages/happy-dom/src/nodes/document/IDocument.ts
+++ b/packages/happy-dom/src/nodes/document/IDocument.ts
@@ -301,7 +301,7 @@ export default interface IDocument extends IParentNode {
 	 * @param [deep=false] "true" to clone deep.
 	 * @returns Cloned node.
 	 */
-	cloneNode(deep: boolean): IDocument;
+	cloneNode(deep?: boolean): IDocument;
 
 	/**
 	 * Adopts a node.
diff --git a/packages/happy-dom/src/nodes/element/IElement.ts b/packages/happy-dom/src/nodes/element/IElement.ts
index d849b615..317bd971 100644
--- a/packages/happy-dom/src/nodes/element/IElement.ts
+++ b/packages/happy-dom/src/nodes/element/IElement.ts
@@ -287,7 +287,7 @@ export default interface IElement extends IChildNode, INonDocumentTypeChildNode,
 	 * @param [deep=false] "true" to clone deep.
 	 * @returns Cloned node.
 	 */
-	cloneNode(deep: boolean): IElement;
+	cloneNode(deep?: boolean): IElement;
 
 	/**
 	 * Inserts a node to the given position.
diff --git a/packages/happy-dom/src/nodes/html-base-element/IHTMLBaseElement.ts b/packages/happy-dom/src/nodes/html-base-element/IHTMLBaseElement.ts
index 6d991c9c..956e966c 100644
--- a/packages/happy-dom/src/nodes/html-base-element/IHTMLBaseElement.ts
+++ b/packages/happy-dom/src/nodes/html-base-element/IHTMLBaseElement.ts
@@ -17,5 +17,5 @@ export default interface IHTMLBaseElement extends IHTMLElement {
 	 * @param [deep=false] "true" to clone deep.
 	 * @returns Cloned node.
 	 */
-	cloneNode(deep: boolean): IHTMLBaseElement;
+	cloneNode(deep?: boolean): IHTMLBaseElement;
 }
diff --git a/packages/happy-dom/src/nodes/html-element/IHTMLElement.ts b/packages/happy-dom/src/nodes/html-element/IHTMLElement.ts
index 35ab764d..309f884c 100644
--- a/packages/happy-dom/src/nodes/html-element/IHTMLElement.ts
+++ b/packages/happy-dom/src/nodes/html-element/IHTMLElement.ts
@@ -72,5 +72,5 @@ export default interface IHTMLElement extends IElement {
 	 * @param [deep=false] "true" to clone deep.
 	 * @returns Cloned node.
 	 */
-	cloneNode(deep: boolean): IHTMLElement;
+	cloneNode(deep?: boolean): IHTMLElement;
 }
diff --git a/packages/happy-dom/src/nodes/html-form-element/IHTMLFormElement.ts b/packages/happy-dom/src/nodes/html-form-element/IHTMLFormElement.ts
index 281b30bd..5d1e99fb 100644
--- a/packages/happy-dom/src/nodes/html-form-element/IHTMLFormElement.ts
+++ b/packages/happy-dom/src/nodes/html-form-element/IHTMLFormElement.ts
@@ -66,5 +66,5 @@ export default interface IHTMLFormElement extends IHTMLElement {
 	 * @param [deep=false] "true" to clone deep.
 	 * @returns Cloned node.
 	 */
-	cloneNode(deep: boolean): IHTMLFormElement;
+	cloneNode(deep?: boolean): IHTMLFormElement;
 }
diff --git a/packages/happy-dom/src/nodes/html-image-element/IHTMLImageElement.ts b/packages/happy-dom/src/nodes/html-image-element/IHTMLImageElement.ts
index ae71dba3..a2a9de27 100644
--- a/packages/happy-dom/src/nodes/html-image-element/IHTMLImageElement.ts
+++ b/packages/happy-dom/src/nodes/html-image-element/IHTMLImageElement.ts
@@ -40,5 +40,5 @@ export default interface IHTMLImageElement extends IHTMLElement {
 	 * @param [deep=false] "true" to clone deep.
 	 * @returns Cloned node.
 	 */
-	cloneNode(deep: boolean): IHTMLImageElement;
+	cloneNode(deep?: boolean): IHTMLImageElement;
 }
diff --git a/packages/happy-dom/src/nodes/html-input-element/IHTMLInputElement.ts b/packages/happy-dom/src/nodes/html-input-element/IHTMLInputElement.ts
index 64452437..2f894297 100644
--- a/packages/happy-dom/src/nodes/html-input-element/IHTMLInputElement.ts
+++ b/packages/happy-dom/src/nodes/html-input-element/IHTMLInputElement.ts
@@ -133,5 +133,5 @@ export default interface IHTMLInputElement extends IHTMLElement {
 	 * @param [deep=false] "true" to clone deep.
 	 * @returns Cloned node.
 	 */
-	cloneNode(deep: boolean): IHTMLInputElement;
+	cloneNode(deep?: boolean): IHTMLInputElement;
 }
diff --git a/packages/happy-dom/src/nodes/html-media-element/IHTMLMediaElement.ts b/packages/happy-dom/src/nodes/html-media-element/IHTMLMediaElement.ts
index 8309e40c..3fad860a 100644
--- a/packages/happy-dom/src/nodes/html-media-element/IHTMLMediaElement.ts
+++ b/packages/happy-dom/src/nodes/html-media-element/IHTMLMediaElement.ts
@@ -106,5 +106,5 @@ export default interface IHTMLMediaElement extends IHTMLElement {
 	 * @param [deep=false] "true" to clone deep.
 	 * @returns Cloned node.
 	 */
-	cloneNode(deep: boolean): IHTMLMediaElement;
+	cloneNode(deep?: boolean): IHTMLMediaElement;
 }
diff --git a/packages/happy-dom/src/nodes/html-script-element/IHTMLScriptElement.ts b/packages/happy-dom/src/nodes/html-script-element/IHTMLScriptElement.ts
index 43c051fd..6c299586 100644
--- a/packages/happy-dom/src/nodes/html-script-element/IHTMLScriptElement.ts
+++ b/packages/happy-dom/src/nodes/html-script-element/IHTMLScriptElement.ts
@@ -22,5 +22,5 @@ export default interface IHTMLScriptElement extends IHTMLElement {
 	 * @param [deep=false] "true" to clone deep.
 	 * @returns Cloned node.
 	 */
-	cloneNode(deep: boolean): IHTMLScriptElement;
+	cloneNode(deep?: boolean): IHTMLScriptElement;
 }
diff --git a/packages/happy-dom/src/nodes/html-slot-element/IHTMLSlotElement.ts b/packages/happy-dom/src/nodes/html-slot-element/IHTMLSlotElement.ts
index c495663f..268d8197 100644
--- a/packages/happy-dom/src/nodes/html-slot-element/IHTMLSlotElement.ts
+++ b/packages/happy-dom/src/nodes/html-slot-element/IHTMLSlotElement.ts
@@ -47,5 +47,5 @@ export default interface IHTMLSlotElement extends IHTMLElement {
 	 * @param [deep=false] "true" to clone deep.
 	 * @returns Cloned node.
 	 */
-	cloneNode(deep: boolean): IHTMLSlotElement;
+	cloneNode(deep?: boolean): IHTMLSlotElement;
 }
diff --git a/packages/happy-dom/src/nodes/html-template-element/IHTMLTemplateElement.ts b/packages/happy-dom/src/nodes/html-template-element/IHTMLTemplateElement.ts
index c4555b94..8582193b 100644
--- a/packages/happy-dom/src/nodes/html-template-element/IHTMLTemplateElement.ts
+++ b/packages/happy-dom/src/nodes/html-template-element/IHTMLTemplateElement.ts
@@ -17,5 +17,5 @@ export default interface IHTMLTemplateElement extends IHTMLElement {
 	 * @param [deep=false] "true" to clone deep.
 	 * @returns Cloned node.
 	 */
-	cloneNode(deep: boolean): IHTMLTemplateElement;
+	cloneNode(deep?: boolean): IHTMLTemplateElement;
 }
diff --git a/packages/happy-dom/src/nodes/html-text-area-element/IHTMLTextAreaElement.ts b/packages/happy-dom/src/nodes/html-text-area-element/IHTMLTextAreaElement.ts
index df5729b4..c71a35a8 100644
--- a/packages/happy-dom/src/nodes/html-text-area-element/IHTMLTextAreaElement.ts
+++ b/packages/happy-dom/src/nodes/html-text-area-element/IHTMLTextAreaElement.ts
@@ -98,5 +98,5 @@ export default interface IHTMLTextAreaElement extends IHTMLElement {
 	 * @param [deep=false] "true" to clone deep.
 	 * @returns Cloned node.
 	 */
-	cloneNode(deep: boolean): IHTMLTextAreaElement;
+	cloneNode(deep?: boolean): IHTMLTextAreaElement;
 }
diff --git a/packages/happy-dom/src/nodes/node/INode.ts b/packages/happy-dom/src/nodes/node/INode.ts
index 52a5f766..4a514b3d 100644
--- a/packages/happy-dom/src/nodes/node/INode.ts
+++ b/packages/happy-dom/src/nodes/node/INode.ts
@@ -38,7 +38,7 @@ export default interface INode extends IEventTarget {
 	connectedCallback?(): void;
 	disconnectedCallback?(): void;
 	getRootNode(options?: { composed: boolean }): INode;
-	cloneNode(deep: boolean): INode;
+	cloneNode(deep?: boolean): INode;
 	appendChild(node: INode): INode;
 	removeChild(node: INode): INode;
 	hasChildNodes(): boolean;
diff --git a/packages/happy-dom/src/nodes/shadow-root/IShadowRoot.ts b/packages/happy-dom/src/nodes/shadow-root/IShadowRoot.ts
index 31fbf450..067904a3 100644
--- a/packages/happy-dom/src/nodes/shadow-root/IShadowRoot.ts
+++ b/packages/happy-dom/src/nodes/shadow-root/IShadowRoot.ts
@@ -9,6 +9,7 @@ export default interface IShadowRoot extends IDocumentFragment {
 	mode: string;
 	innerHTML: string;
 	host: IElement;
+	readonly activeElement: IElement | null;
 
 	// Events
 	onslotchange: (event: Event) => void | null;
@@ -20,5 +21,5 @@ export default interface IShadowRoot extends IDocumentFragment {
 	 * @param [deep=false] "true" to clone deep.
 	 * @returns Cloned node.
 	 */
-	cloneNode(deep: boolean): IShadowRoot;
+	cloneNode(deep?: boolean): IShadowRoot;
 }
diff --git a/packages/happy-dom/src/nodes/shadow-root/ShadowRoot.ts b/packages/happy-dom/src/nodes/shadow-root/ShadowRoot.ts
index 8fba913b..9bbdad41 100644
--- a/packages/happy-dom/src/nodes/shadow-root/ShadowRoot.ts
+++ b/packages/happy-dom/src/nodes/shadow-root/ShadowRoot.ts
@@ -52,7 +52,7 @@ export default class ShadowRoot extends DocumentFragment implements IShadowRoot
 	 *
 	 * @returns Active element.
 	 */
-	public get activeElement(): IHTMLElement {
+	public get activeElement(): IHTMLElement | null {
 		const activeElement: IHTMLElement = this.ownerDocument['_activeElement'];
 		if (activeElement && activeElement.isConnected && activeElement.getRootNode() === this) {
 			return activeElement;
diff --git a/packages/happy-dom/src/nodes/svg-element/ISVGSVGElement.ts b/packages/happy-dom/src/nodes/svg-element/ISVGSVGElement.ts
index 75f38534..bf7d8b38 100644
--- a/packages/happy-dom/src/nodes/svg-element/ISVGSVGElement.ts
+++ b/packages/happy-dom/src/nodes/svg-element/ISVGSVGElement.ts
@@ -157,5 +157,5 @@ export default interface ISVGSVGElement extends ISVGGraphicsElement {
 	 * @param [deep=false] "true" to clone deep.
 	 * @returns Cloned node.
 	 */
-	cloneNode(deep: boolean): ISVGSVGElement;
+	cloneNode(deep?: boolean): ISVGSVGElement;
 }
diff --git a/packages/happy-dom/src/window/Window.ts b/packages/happy-dom/src/window/Window.ts
index 9bfa1a92..3f25300e 100644
--- a/packages/happy-dom/src/window/Window.ts
+++ b/packages/happy-dom/src/window/Window.ts
@@ -23,7 +23,7 @@ import HTMLLabelElement from '../nodes/html-label-element/HTMLLabelElement';
 import HTMLMetaElement from '../nodes/html-meta-element/HTMLMetaElement';
 import HTMLMediaElement from '../nodes/html-media-element/HTMLMediaElement';
 import HTMLAudioElement from '../nodes/html-audio-element/HTMLAudioElement';
-import { default as AudioImplementation } from '../nodes/html-audio-element/Audio';
+import AudioImplementation from '../nodes/html-audio-element/Audio';
 import HTMLVideoElement from '../nodes/html-video-element/HTMLVideoElement';
 import HTMLBaseElement from '../nodes/html-base-element/HTMLBaseElement';
 import HTMLIFrameElement from '../nodes/html-iframe-element/HTMLIFrameElement';
@@ -33,7 +33,7 @@ import SVGElement from '../nodes/svg-element/SVGElement';
 import SVGGraphicsElement from '../nodes/svg-element/SVGGraphicsElement';
 import HTMLScriptElement from '../nodes/html-script-element/HTMLScriptElement';
 import HTMLImageElement from '../nodes/html-image-element/HTMLImageElement';
-import { default as ImageImplementation } from '../nodes/html-image-element/Image';
+import ImageImplementation from '../nodes/html-image-element/Image';
 import DocumentFragment from '../nodes/document-fragment/DocumentFragment';
 import CharacterData from '../nodes/character-data/CharacterData';
 import NodeIterator from '../tree-walker/NodeIterator';
@@ -52,13 +52,13 @@ import Location from '../location/Location';
 import NonImplementedEventTypes from '../event/NonImplementedEventTypes';
 import MutationObserver from '../mutation-observer/MutationObserver';
 import NonImplemenetedElementClasses from '../config/NonImplemenetedElementClasses';
-import { default as DOMParserImplementation } from '../dom-parser/DOMParser';
+import DOMParserImplementation from '../dom-parser/DOMParser';
 import XMLSerializer from '../xml-serializer/XMLSerializer';
 import ResizeObserver from '../resize-observer/ResizeObserver';
 import Blob from '../file/Blob';
 import File from '../file/File';
 import DOMException from '../exception/DOMException';
-import { default as FileReaderImplementation } from '../file/FileReader';
+import FileReaderImplementation from '../file/FileReader';
 import History from '../history/History';
 import CSSStyleSheet from '../css/CSSStyleSheet';
 import CSSStyleDeclaration from '../css/declaration/CSSStyleDeclaration';
@@ -93,8 +93,8 @@ import IRequestInit from '../fetch/types/IRequestInit';
 import IHeaders from '../fetch/types/IHeaders';
 import IHeadersInit from '../fetch/types/IHeadersInit';
 import Headers from '../fetch/Headers';
-import { default as RequestImplementation } from '../fetch/Request';
-import { default as ResponseImplementation } from '../fetch/Response';
+import RequestImplementation from '../fetch/Request';
+import ResponseImplementation from '../fetch/Response';
 import Storage from '../storage/Storage';
 import IWindow from './IWindow';
 import HTMLCollection from '../nodes/element/HTMLCollection';
@@ -108,7 +108,7 @@ import MimeTypeArray from '../navigator/MimeTypeArray';
 import Plugin from '../navigator/Plugin';
 import PluginArray from '../navigator/PluginArray';
 import Fetch from '../fetch/Fetch';
-import { default as RangeImplementation } from '../range/Range';
+import RangeImplementation from '../range/Range';
 import DOMRect from '../nodes/element/DOMRect';
 import VMGlobalPropertyScript from './VMGlobalPropertyScript';
 import * as PerfHooks from 'perf_hooks';
@@ -296,7 +296,7 @@ export default class Window extends EventTarget implements IWindow {
 	public readonly AbortSignal = AbortSignal;
 	public readonly FormData = FormData;
 	public readonly XMLHttpRequest;
-	public readonly DOMParser;
+	public readonly DOMParser: typeof DOMParserImplementation;
 	public readonly Range;
 	public readonly FileReader;
 	public readonly Image;


Test patch:
diff --git a/packages/happy-dom/test/dom-parser/DOMParser.test.ts b/packages/happy-dom/test/dom-parser/DOMParser.test.ts
index 213697b9..e4930946 100644
--- a/packages/happy-dom/test/dom-parser/DOMParser.test.ts
+++ b/packages/happy-dom/test/dom-parser/DOMParser.test.ts
@@ -1,10 +1,11 @@
 import Window from '../../src/window/Window';
 import XMLSerializer from '../../src/xml-serializer/XMLSerializer';
+import DOMParser from '../../src/dom-parser/DOMParser';
 import DOMParserHTML from './data/DOMParserHTML';
 
 describe('DOMParser', () => {
-	let domParser;
-	let window;
+	let domParser: DOMParser;
+	let window: Window;
 
 	beforeEach(() => {
 		window = new Window({
diff --git a/packages/happy-dom/test/mutation-observer/MutationObserver.test.ts b/packages/happy-dom/test/mutation-observer/MutationObserver.test.ts
index 644bd6b5..1e241afd 100644
--- a/packages/happy-dom/test/mutation-observer/MutationObserver.test.ts
+++ b/packages/happy-dom/test/mutation-observer/MutationObserver.test.ts
@@ -1,9 +1,10 @@
 import Window from '../../src/window/Window';
+import Document from '../../src/nodes/document/Document';
 import MutationObserver from '../../src/mutation-observer/MutationObserver';
 
 describe('MutationObserver', () => {
-	let window;
-	let document;
+	let window: Window;
+	let document: Document;
 
 	beforeEach(() => {
 		window = new Window();
diff --git a/packages/happy-dom/test/nodes/character-data/CharacterDataUtility.test.ts b/packages/happy-dom/test/nodes/character-data/CharacterDataUtility.test.ts
index 6e50fb9a..418d96d4 100644
--- a/packages/happy-dom/test/nodes/character-data/CharacterDataUtility.test.ts
+++ b/packages/happy-dom/test/nodes/character-data/CharacterDataUtility.test.ts
@@ -1,9 +1,10 @@
 import Window from '../../../src/window/Window';
+import Document from '../../../src/nodes/document/Document';
 import CharacterDataUtility from '../../../src/nodes/character-data/CharacterDataUtility';
 
 describe('CharacterDataTest', () => {
-	let window;
-	let document;
+	let window: Window;
+	let document: Document;
 
 	beforeEach(() => {
 		window = new Window();
diff --git a/packages/happy-dom/test/nodes/child-node/ChildNodeUtility.test.ts b/packages/happy-dom/test/nodes/child-node/ChildNodeUtility.test.ts
index 6405a723..313b0d12 100644
--- a/packages/happy-dom/test/nodes/child-node/ChildNodeUtility.test.ts
+++ b/packages/happy-dom/test/nodes/child-node/ChildNodeUtility.test.ts
@@ -1,9 +1,10 @@
 import Window from '../../../src/window/Window';
+import Document from '../../../src/nodes/document/Document';
 import ChildNodeUtility from '../../../src/nodes/child-node/ChildNodeUtility';
 
 describe('ChildNodeUtility', () => {
-	let window;
-	let document;
+	let window: Window;
+	let document: Document;
 
 	beforeEach(() => {
 		window = new Window();
diff --git a/packages/happy-dom/test/nodes/child-node/NonDocumentChildNodeUtility.test.ts b/packages/happy-dom/test/nodes/child-node/NonDocumentChildNodeUtility.test.ts
index 390a9ccd..266d73fd 100644
--- a/packages/happy-dom/test/nodes/child-node/NonDocumentChildNodeUtility.test.ts
+++ b/packages/happy-dom/test/nodes/child-node/NonDocumentChildNodeUtility.test.ts
@@ -1,9 +1,10 @@
 import Window from '../../../src/window/Window';
+import Document from '../../../src/nodes/document/Document';
 import NonDocumentChildNodeUtility from '../../../src/nodes/child-node/NonDocumentChildNodeUtility';
 
 describe('NonDocumentChildNodeUtility', () => {
-	let window;
-	let document;
+	let window: Window;
+	let document: Document;
 
 	beforeEach(() => {
 		window = new Window();
diff --git a/packages/happy-dom/test/nodes/document-fragment/DocumentFragment.test.ts b/packages/happy-dom/test/nodes/document-fragment/DocumentFragment.test.ts
index 8ac23cdf..426f9144 100644
--- a/packages/happy-dom/test/nodes/document-fragment/DocumentFragment.test.ts
+++ b/packages/happy-dom/test/nodes/document-fragment/DocumentFragment.test.ts
@@ -1,4 +1,7 @@
 import Window from '../../../src/window/Window';
+import Document from '../../../src/nodes/document/Document';
+import DocumentFragment from '../../../src/nodes/document-fragment/DocumentFragment';
+import IDocumentFragment from '../../../src/nodes/document-fragment/IDocumentFragment';
 import Node from '../../../src/nodes/node/Node';
 import ParentNodeUtility from '../../../src/nodes/parent-node/ParentNodeUtility';
 import QuerySelector from '../../../src/query-selector/QuerySelector';
@@ -8,9 +11,9 @@ import INodeList from '../../../src/nodes/node/INodeList';
 import IElement from '../../../src/nodes/element/IElement';
 
 describe('DocumentFragment', () => {
-	let window;
-	let document;
-	let documentFragment;
+	let window: Window;
+	let document: Document;
+	let documentFragment: IDocumentFragment;
 
 	beforeEach(() => {
 		window = new Window();
@@ -294,7 +297,7 @@ describe('DocumentFragment', () => {
 			const clone = documentFragment.cloneNode(false);
 
 			expect(clone.nodeType).toBe(Node.DOCUMENT_FRAGMENT_NODE);
-			expect(clone._rootNode).toBe(clone);
+			expect((<DocumentFragment>clone)._rootNode).toBe(clone);
 			expect(clone.childNodes.length).toBe(0);
 			expect(clone.children.length).toBe(0);
 		});
@@ -311,7 +314,7 @@ describe('DocumentFragment', () => {
 			const clone = documentFragment.cloneNode(true);
 
 			expect(clone.nodeType).toBe(Node.DOCUMENT_FRAGMENT_NODE);
-			expect(clone._rootNode).toBe(clone);
+			expect((<DocumentFragment>clone)._rootNode).toBe(clone);
 			expect(clone.childNodes.length).toBe(3);
 			expect(Array.from(clone.children)).toEqual(
 				Array.from(clone.childNodes.filter((node) => node.nodeType === Node.ELEMENT_NODE))
diff --git a/packages/happy-dom/test/nodes/node/Node.test.ts b/packages/happy-dom/test/nodes/node/Node.test.ts
index d7ebb495..d7d8823f 100644
--- a/packages/happy-dom/test/nodes/node/Node.test.ts
+++ b/packages/happy-dom/test/nodes/node/Node.test.ts
@@ -1,6 +1,8 @@
 import Window from '../../../src/window/Window';
+import Document from '../../../src/nodes/document/Document';
 import Node from '../../../src/nodes/node/Node';
 import HTMLElement from '../../../src/nodes/html-element/HTMLElement';
+import HTMLTemplateElement from '../../../src/nodes/html-template-element/HTMLTemplateElement';
 import Event from '../../../src/event/Event';
 import Text from '../../../src/nodes/text/Text';
 
@@ -56,8 +58,8 @@ class CustomButtonElement extends HTMLElement {
 }
 
 describe('Node', () => {
-	let window;
-	let document;
+	let window: Window;
+	let document: Document;
 	let customElementOutput;
 
 	beforeEach(() => {
@@ -405,7 +407,7 @@ describe('Node', () => {
 
 		// See: https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment
 		it('Append the child nodes instead of the actual node if the type is DocumentFragment.', () => {
-			const template = document.createElement('template');
+			const template = <HTMLTemplateElement>document.createElement('template');
 
 			template.innerHTML = '<div>Div</div><span>Span</span>';
 
@@ -467,7 +469,7 @@ describe('Node', () => {
 		it('Insert the child nodes instead of the actual node before another reference Node if the type is DocumentFragment.', () => {
 			const child1 = document.createElement('span');
 			const child2 = document.createElement('span');
-			const template = document.createElement('template');
+			const template = <HTMLTemplateElement>document.createElement('template');
 			const parent = document.createElement('div');
 
 			template.innerHTML = '<div>Template DIV 1</div><span>Template SPAN 1</span>';
diff --git a/packages/happy-dom/test/nodes/shadow-root/ShadowRoot.test.ts b/packages/happy-dom/test/nodes/shadow-root/ShadowRoot.test.ts
index 3578e113..654e3308 100644
--- a/packages/happy-dom/test/nodes/shadow-root/ShadowRoot.test.ts
+++ b/packages/happy-dom/test/nodes/shadow-root/ShadowRoot.test.ts
@@ -1,10 +1,11 @@
 import IHTMLElement from '../../../src/nodes/html-element/IHTMLElement';
 import Window from '../../../src/window/Window';
+import Document from '../../../src/nodes/document/Document';
 import CustomElement from '../../CustomElement';
 
 describe('ShadowRoot', () => {
-	let window;
-	let document;
+	let window: Window;
+	let document: Document;
 
 	beforeEach(() => {
 		window = new Window();
@@ -22,8 +23,8 @@ describe('ShadowRoot', () => {
 			shadowRoot.innerHTML = '<div attr1="value1" attr2="value2"><span>Test</span></div>';
 			expect(shadowRoot.childNodes.length).toBe(1);
 			expect(shadowRoot.childNodes[0].childNodes.length).toBe(1);
-			expect(shadowRoot.childNodes[0].tagName).toBe('DIV');
-			expect(shadowRoot.childNodes[0].childNodes[0].tagName).toBe('SPAN');
+			expect((<IHTMLElement>shadowRoot.childNodes[0]).tagName).toBe('DIV');
+			expect((<IHTMLElement>shadowRoot.childNodes[0].childNodes[0]).tagName).toBe('SPAN');
 		});
 	});
 
diff --git a/packages/happy-dom/test/tree-walker/NodeIterator.test.ts b/packages/happy-dom/test/tree-walker/NodeIterator.test.ts
index a4834461..48f93840 100644
--- a/packages/happy-dom/test/tree-walker/NodeIterator.test.ts
+++ b/packages/happy-dom/test/tree-walker/NodeIterator.test.ts
@@ -1,4 +1,5 @@
 import Window from '../../src/window/Window';
+import Document from '../../src/nodes/document/Document';
 import NodeFilter from '../../src/tree-walker/NodeFilter';
 import Element from '../../src/nodes/element/Element';
 import Comment from '../../src/nodes/comment/Comment';
@@ -16,8 +17,8 @@ const NODE_TO_STRING = (node: Node): string => {
 };
 
 describe('NodeIterator', () => {
-	let window;
-	let document;
+	let window: Window;
+	let document: Document;
 
 	beforeEach(() => {
 		window = new Window();
diff --git a/packages/happy-dom/test/tree-walker/TreeWalker.test.ts b/packages/happy-dom/test/tree-walker/TreeWalker.test.ts
index 56581ba8..1da009ea 100644
--- a/packages/happy-dom/test/tree-walker/TreeWalker.test.ts
+++ b/packages/happy-dom/test/tree-walker/TreeWalker.test.ts
@@ -1,4 +1,5 @@
 import Window from '../../src/window/Window';
+import Document from '../../src/nodes/document/Document';
 import NodeFilter from '../../src/tree-walker/NodeFilter';
 import Element from '../../src/nodes/element/Element';
 import Comment from '../../src/nodes/comment/Comment';
@@ -16,8 +17,8 @@ const NODE_TO_STRING = (node: Node): string => {
 };
 
 describe('TreeWalker', () => {
-	let window;
-	let document;
+	let window: Window;
+	let document: Document;
 
 	beforeEach(() => {
 		window = new Window();
@@ -200,8 +201,8 @@ describe('TreeWalker', () => {
 		it('Returns the first child node.', () => {
 			const treeWalker = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT);
 			const node = treeWalker.nextNode();
-			expect(node.firstChild !== null).toBe(true);
-			expect(treeWalker.firstChild() === node.firstElementChild).toBe(true);
+			expect(node).toBeInstanceOf(Element);
+			expect(treeWalker.firstChild()).toBe((<Element>node).firstElementChild);
 		});
 	});
 });