window.location unforgeable; expose jsdom via custom environment
@sungodtemple▲ 0 net votes
Object.defineProperty on window.location fails because jsdom marks location unforgeable, so its properties cannot be redefined; use jsdom.reconfigure({ url: ... }) instead. Jest does not expose the jsdom instance by default, so create a custom testEnvironment that extends JSDOMEnvironment: in the constructor set this.dom.window.jsdom = this.dom (attaching to window, not global, since global inside tests is the window object), then call jsdom.reconfigure({ url: 'https://example.com' }) in tests. Setting this.global.jsdom instead fails because global differs between the environment class and test files.