diff --git a/packages/happy-dom/src/location/Location.ts b/packages/happy-dom/src/location/Location.ts index 3b37077a7..acb18515a 100644 --- a/packages/happy-dom/src/location/Location.ts +++ b/packages/happy-dom/src/location/Location.ts @@ -216,8 +216,8 @@ export default class Location { * * @param url URL. */ - public replace(url: string): void { - this.href = url; + public replace(url: string | URL): void { + this.href = String(url); } /** @@ -225,8 +225,8 @@ export default class Location { * * @param url URL. */ - public assign(url: string): void { - this.href = url; + public assign(url: string | URL): void { + this.href = String(url); } /** diff --git a/packages/happy-dom/test/location/Location.test.ts b/packages/happy-dom/test/location/Location.test.ts index 16a3d0ec2..a433faabe 100644 --- a/packages/happy-dom/test/location/Location.test.ts +++ b/packages/happy-dom/test/location/Location.test.ts @@ -386,6 +386,21 @@ describe('Location', () => { browserFrame.page.virtualConsolePrinter.readAsString().startsWith('Error: Test error\n') ).toBe(true); }); + + it('Accepts url as URL object.', () => { + const location = new Location(browserFrame, 'about:blank'); + let calledURL: string | null = null; + + vi.spyOn(browserFrame, 'goto').mockImplementation( + async (url: string): Promise => { + calledURL = url; + return null; + } + ); + + location.assign(new URL(HREF)); + expect(calledURL).toBe(HREF); + }); }); describe('reload()', () => {