Skip to content

Commit

Permalink
Merge pull request #674 from capricorn86/task/673-default-windowinner…
Browse files Browse the repository at this point in the history
…width-to-1024

#673@major: Changes the default value for window.innerWidth to 1024 a…
  • Loading branch information
capricorn86 committed Dec 7, 2022
2 parents b4a812e + 133403f commit a85a84f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
8 changes: 4 additions & 4 deletions packages/happy-dom/README.md
Expand Up @@ -223,15 +223,15 @@ window.happyDOM.cancelAsync();
Sets the property `window.innerWidth` and dispatches a "resize" event.

```javascript
window.happyDOM.setInnerWidth(1024);
window.happyDOM.setInnerWidth(1920);
```

**setInnerHeight()**

Sets the property `window.innerHeight` and dispatches a "resize" event.

```javascript
window.happyDOM.setInnerHeight(768);
window.happyDOM.setInnerHeight(1080);
```

**setURL()**
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions packages/happy-dom/src/window/Window.ts
Expand Up @@ -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.
*/
Expand All @@ -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;
Expand Down
13 changes: 9 additions & 4 deletions packages/happy-dom/test/window/Window.test.ts
Expand Up @@ -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');
});
});

Expand Down

0 comments on commit a85a84f

Please sign in to comment.