Skip to content

Commit

Permalink
fix: [capricorn86#1568] Accept URL in Location.assign and Location.re…
Browse files Browse the repository at this point in the history
…place
  • Loading branch information
silverwind committed Oct 21, 2024
1 parent afd256b commit b122bb0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/happy-dom/src/location/Location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,17 @@ 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);
}

/**
* Loads the resource at the URL provided in parameter.
*
* @param url URL.
*/
public assign(url: string): void {
this.href = url;
public assign(url: string | URL): void {
this.href = String(url);
}

/**
Expand Down
15 changes: 15 additions & 0 deletions packages/happy-dom/test/location/Location.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 | URL): Promise<Response | null> => {
calledURL = String(url);
return null;
}
);

location.assign(new URL(HREF));
expect(calledURL).toBe(HREF);
});
});

describe('reload()', () => {
Expand Down

0 comments on commit b122bb0

Please sign in to comment.