Repository: capricorn86/happy-dom (ts)

Issue:
TypeError in window constructor
**Describe the bug**

```javascript
const { Window } = require('happy-dom');

const window = new Window({
    innerWidth: 1024,
    innerHeight: 768,
    url: 'http://localhost:8080',
});

console.log(window);
/*
            this.location.href = options.url;
                               ^

TypeError: Cannot set properties of undefined (setting 'href')
*/
```


Pull request description:
#627@patch: Fix location.href initialization in Window.
Closes #627 

Patch:
diff --git a/packages/happy-dom/src/window/Window.ts b/packages/happy-dom/src/window/Window.ts
index ac23a14f..8f988f74 100644
--- a/packages/happy-dom/src/window/Window.ts
+++ b/packages/happy-dom/src/window/Window.ts
@@ -252,20 +252,20 @@ export default class Window extends EventTarget implements IWindow {
 
 	// Public Properties
 	public readonly document: Document;
-	public readonly customElements: CustomElementRegistry = new CustomElementRegistry();
-	public readonly location = new Location();
-	public readonly history = new History();
-	public readonly navigator = new Navigator();
+	public readonly customElements: CustomElementRegistry;
+	public readonly location: Location;
+	public readonly history: History;
+	public readonly navigator: Navigator;
 	public readonly console = console;
 	public readonly self = this;
 	public readonly top = this;
 	public readonly parent = this;
 	public readonly window = this;
 	public readonly globalThis = this;
-	public readonly screen = new Screen();
+	public readonly screen: Screen;
 	public readonly devicePixelRatio = 1;
-	public readonly sessionStorage = new Storage();
-	public readonly localStorage = new Storage();
+	public readonly sessionStorage: Storage;
+	public readonly localStorage: Storage;
 	public readonly performance = PerfHooks.performance;
 	public readonly innerWidth: number;
 	public readonly innerHeight: number;
@@ -350,6 +350,14 @@ export default class Window extends EventTarget implements IWindow {
 	constructor(options?: { innerWidth?: number; innerHeight?: number; url?: string }) {
 		super();
 
+		this.customElements = new CustomElementRegistry();
+		this.location = new Location();
+		this.navigator = new Navigator();
+		this.history = new History();
+		this.screen = new Screen();
+		this.sessionStorage = new Storage();
+		this.localStorage = new Storage();
+
 		this.innerWidth = options?.innerWidth ? options.innerWidth : 0;
 		this.innerHeight = options?.innerHeight ? options.innerHeight : 0;
 


Test patch:
diff --git a/packages/happy-dom/test/window/Window.test.ts b/packages/happy-dom/test/window/Window.test.ts
index 8c8a9283..188e049a 100644
--- a/packages/happy-dom/test/window/Window.test.ts
+++ b/packages/happy-dom/test/window/Window.test.ts
@@ -79,6 +79,18 @@ describe('Window', () => {
 			expect(secondComment.ownerDocument === secondWindow.document).toBe(true);
 			expect(thirdComment.ownerDocument === thirdWindow.document).toBe(true);
 		});
+
+		it('Initializes by using given options', () => {
+			const windowWithOptions = new Window({
+				innerWidth: 1024,
+				innerHeight: 768,
+				url: 'http://localhost:8080'
+			});
+
+			expect(windowWithOptions.innerWidth).toBe(1024);
+			expect(windowWithOptions.innerHeight).toBe(768);
+			expect(windowWithOptions.location.href).toBe('http://localhost:8080/');
+		});
 	});
 
 	describe('get Object()', () => {