Skip to content

Commit

Permalink
fix: [#1664] Support using URL as an object for URL:s when using the …
Browse files Browse the repository at this point in the history
…Browser API (#1672)
  • Loading branch information
capricorn86 authored Jan 7, 2025
1 parent 00b34b4 commit 4732136
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class BrowserFrameURL {
* @returns Relative URL.
*/
public static getRelativeURL(frame: IBrowserFrame, url: string | URL): URL {
url = (url instanceof URL ? url.toString() : url) || 'about:blank';
url = url ? String(url) : 'about:blank';

if (url.startsWith('about:') || url.startsWith('javascript:')) {
return new URL(url);
Expand Down
8 changes: 7 additions & 1 deletion packages/happy-dom/test/browser/BrowserFrame.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,16 @@ describe('BrowserFrame', () => {
it('Sets the document URL.', () => {
const browser = new Browser();
const page = browser.defaultContext.newPage();
const location = page.mainFrame.window.location;
page.mainFrame.url = 'http://localhost:3000';
expect(page.mainFrame.window.location.href).toBe('http://localhost:3000/');
});

it(`Supports URL as an object.`, async () => {
const browser = new Browser();
const page = browser.defaultContext.newPage();
page.mainFrame.url = <string>(<unknown>{ toString: () => 'http://localhost:3000' });
expect(page.mainFrame.window.location.href).toBe('http://localhost:3000/');
});
});

describe('waitUntilComplete()', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,19 @@ describe('DetachedBrowserFrame', () => {
browser.defaultContext.pages[0].mainFrame
);
const page = browser.defaultContext.pages[0];
const location = page.mainFrame.window.location;
page.mainFrame.url = 'http://localhost:3000';
expect(page.mainFrame.window.location.href).toBe('http://localhost:3000/');
});

it(`Supports URL as an object.`, async () => {
const browser = new DetachedBrowser(BrowserWindow);
browser.defaultContext.pages[0].mainFrame.window = new BrowserWindow(
browser.defaultContext.pages[0].mainFrame
);
const page = browser.defaultContext.pages[0];
page.mainFrame.url = <string>(<unknown>{ toString: () => 'http://localhost:3000' });
expect(page.mainFrame.window.location.href).toBe('http://localhost:3000/');
});
});

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

0 comments on commit 4732136

Please sign in to comment.