Skip to content

Latest commit

 

History

History
17 lines (13 loc) · 580 Bytes

define-window-location-for-individual-test.md

File metadata and controls

17 lines (13 loc) · 580 Bytes

Define window.location.href for an individual test

To set the value of window.location.href for a single test in Jest, replace the window global object:

global.window = Object.create(window);
Object.defineProperty(window, 'location', {
  value: {
    href: `https://my-test-url.com/some-path`
  },
  writable: true,
});

The writable property is important to be able to set this value again in a separate test within the same suite.

Note: This solution seems verison dependent. See this discussion on Github.