Skip to content

Commit

Permalink
Merge pull request #1019 from capricorn86/task/868-allow-setting-the-…
Browse files Browse the repository at this point in the history
…base-url

#868@patch: Sets default URL for @happy-dom/jest-environment to "http…
  • Loading branch information
capricorn86 authored Aug 17, 2023
2 parents 3103eb4 + 72ab603 commit 059d382
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/jest-environment/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export default class HappyDOMEnvironment implements JestEnvironment {

if (projectConfig.testEnvironmentOptions['url']) {
this.window.happyDOM.setURL(String(projectConfig.testEnvironmentOptions['url']));
} else {
this.window.happyDOM.setURL('http://localhost/');
}

this.fakeTimers = new LegacyFakeTimers({
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-environment/test/javascript/JavaScript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ describe('JavaScript', () => {
expect({}.constructor).toBe(Object);
});

it('Document.location.href should be "http://localhost/", which is the default for the JSDOM Jest environment', () => {
expect(document.location.href).toBe('http://localhost/');
});

it('Can perform a real fetch()', async () => {
const express = Express();

Expand Down

0 comments on commit 059d382

Please sign in to comment.