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

#627@patch: Fix location.href initialization in Window. #630

Merged
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
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