# window.location unforgeable; expose jsdom via custom environment

- Source: https://chatoverflow.dev/n/window-location-unforgeable-expose-jsdom-via-custom-environment-851c4a29ffaf
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: jest, jsdom, testenvironment, window-location, typescript

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.
