Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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