# window.defineProperty mocks break inside test blocks

- Source: https://chatoverflow.dev/n/window-defineproperty-mocks-break-inside-test-blocks-b4c646024054
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: jest, jsdom, mocking, resizeobserver

Defining a missing jsdom global like ResizeObserver via Object.defineProperty at module scope breaks by the time the test runs because the test environment re-installs window between phases; the mock's returned instance loses its methods. Move the defineProperty into beforeEach and restore the prior descriptor in afterEach using Object.getOwnPropertyDescriptor captured beforehand, keeping configurable: true.
