Repository: capricorn86/happy-dom
Pull request #674 (2022-12-07 18:30:22)

#673@major: Changes the default value for window.innerWidth to 1024 a…
…nd window.innerHeight to 768.


Patch:
diff --git a/packages/happy-dom/README.md b/packages/happy-dom/README.md
index af769ea4..de847fa4 100644
--- a/packages/happy-dom/README.md
+++ b/packages/happy-dom/README.md
@@ -223,7 +223,7 @@ window.happyDOM.cancelAsync();
 Sets the property `window.innerWidth` and dispatches a "resize" event.
 
 ```javascript
-window.happyDOM.setInnerWidth(1024);
+window.happyDOM.setInnerWidth(1920);
 ```
 
 **setInnerHeight()**
@@ -231,7 +231,7 @@ window.happyDOM.setInnerWidth(1024);
 Sets the property `window.innerHeight` and dispatches a "resize" event.
 
 ```javascript
-window.happyDOM.setInnerHeight(768);
+window.happyDOM.setInnerHeight(1080);
 ```
 
 **setURL()**
@@ -250,8 +250,8 @@ Set by constructor:
 
 ```javascript
 const window = new Window({
-	innerWidth: 1024,
-	innerHeight: 768,
+	innerWidth: 1920,
+	innerHeight: 1080,
 	url: 'https://localhost:8080',
 	settings: {
 		disableJavaScriptFileLoading: true,
diff --git a/packages/happy-dom/src/window/Window.ts b/packages/happy-dom/src/window/Window.ts
index ed4854f9..fa9e3590 100644
--- a/packages/happy-dom/src/window/Window.ts
+++ b/packages/happy-dom/src/window/Window.ts
@@ -359,8 +359,8 @@ export default class Window extends EventTarget implements IWindow {
 	 * Constructor.
 	 *
 	 * @param [options] Options.
-	 * @param [options.innerWidth] Inner width.
-	 * @param [options.innerHeight] Inner height.
+	 * @param [options.innerWidth] Inner width. Defaults to "1024".
+	 * @param [options.innerHeight] Inner height. Defaults to "768".
 	 * @param [options.url] URL.
 	 * @param [options.settings] Settings.
 	 */
@@ -380,8 +380,8 @@ export default class Window extends EventTarget implements IWindow {
 		this.sessionStorage = new Storage();
 		this.localStorage = new Storage();
 
-		this.innerWidth = options?.innerWidth ? options.innerWidth : 0;
-		this.innerHeight = options?.innerHeight ? options.innerHeight : 0;
+		this.innerWidth = options?.innerWidth ? options.innerWidth : 1024;
+		this.innerHeight = options?.innerHeight ? options.innerHeight : 768;
 
 		if (options?.url) {
 			this.location.href = options.url;


Test patch:
diff --git a/packages/happy-dom/test/window/Window.test.ts b/packages/happy-dom/test/window/Window.test.ts
index 857ed964..92fb7aa5 100644
--- a/packages/happy-dom/test/window/Window.test.ts
+++ b/packages/happy-dom/test/window/Window.test.ts
@@ -79,14 +79,19 @@ describe('Window', () => {
 
 		it('Initializes by using given options', () => {
 			const windowWithOptions = new Window({
-				innerWidth: 1024,
-				innerHeight: 768,
+				innerWidth: 1920,
+				innerHeight: 1080,
 				url: 'http://localhost:8080'
 			});
+			const windowWithoutOptions = new Window();
 
-			expect(windowWithOptions.innerWidth).toBe(1024);
-			expect(windowWithOptions.innerHeight).toBe(768);
+			expect(windowWithOptions.innerWidth).toBe(1920);
+			expect(windowWithOptions.innerHeight).toBe(1080);
 			expect(windowWithOptions.location.href).toBe('http://localhost:8080/');
+
+			expect(windowWithoutOptions.innerWidth).toBe(1024);
+			expect(windowWithoutOptions.innerHeight).toBe(768);
+			expect(windowWithoutOptions.location.href).toBe('about:blank');
 		});
 	});