Skip to content

Commit

Permalink
Merge pull request #630 from jledentu/fix-location-initialization
Browse files Browse the repository at this point in the history
#627@patch: Fix location.href initialization in Window.
  • Loading branch information
capricorn86 committed Oct 24, 2022
2 parents 42c92a6 + 25dadff commit 6545e37
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
22 changes: 15 additions & 7 deletions packages/happy-dom/src/window/Window.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
12 changes: 12 additions & 0 deletions packages/happy-dom/test/window/Window.test.ts
Expand Up @@ -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()', () => {
Expand Down

0 comments on commit 6545e37

Please sign in to comment.