## TL;DR
Since Jest 28 the default test environment is `node`, not `jsdom`, so `window` does not exist unless you opt in. Install `jest-environment-jsdom` and set `testEnvironment: 'jsdom'` in the Jest config. That one change fixes every `window is not defined` failure at once.

## Error
```text
ReferenceError: window is not defined
  at Object.[anonymous] (src/components/Button.test.js:3:1)
```

## Steps
1. Install the environment package: `npm install --save-dev jest-environment-jsdom`. Expected: it appears in devDependencies.
2. Set `testEnvironment: 'jsdom'` in `jest.config.js` (or under the `jest` key in package.json). Expected: the config loads with no "test environment not found" error.
3. Re-run the suite. Expected: `window`, `document`, and other DOM APIs resolve in tests.

## When to use
- `window is not defined` (or `document is not defined`) after upgrading to Jest 28+.
- A fresh Jest install where component tests touch the DOM.
- You relied on the old default and never set `testEnvironment` explicitly.

## When not to use
- The error comes from a bundler or a real browser runtime, not Jest.
- Fine-tuning jsdom behavior (url, pretendToBeVisual) once the environment loads.
- You are on Jest 27 or earlier (jsdom was the default there).

## Tool compatibility
- Jest 28, 29, and 30 with a matching `jest-environment-jsdom` major version.
- Jest 27 and earlier need no change (jsdom was the default).

## Variant phrasings
### jest window is not defined after upgrading to jest 28
The upgrade changed the default environment; this is the fix.
### ReferenceError document is not defined jest
Same cause and same fix; `document` comes from the same jsdom environment.

## Why it happens
Jest 27 and earlier defaulted to jsdom. Jest 28 flipped the default to `node` for speed and split jsdom into a separate package you must install. Tests written against the old default break with `window is not defined` until you opt back in.

## Edge cases
- Some tests need node (API tests): set the environment per file with a docblock pragma instead of globally.
- Still fails after the fix: you may have two Jest versions installed; check which config the runner actually loads.
- The `jest-environment-jsdom` major version must match your Jest major version.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_W5wHBlHeVOziP8l4Y-dsQw
