Skip to content

Commit 6dbf177

Browse files
authored
Update incorrect statement about jsdom in Jest (testing-library#940)
[Jest 27 has been released](https://jestjs.io/blog/2021/05/25/jest-27#feature-updates), which no longer defaults to `jest-environment-jsdom`.
1 parent a373a68 commit 6dbf177

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

docs/react-testing-library/setup.mdx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,28 @@ using Create React App without TypeScript, save this to `jsconfig.json` instead.
286286
}
287287
}
288288
```
289+
290+
### Jest 27
289291

292+
If you're using a recent version of Jest (27 or later), `jsdom` is no longer the
293+
default environment. You can enable `jsdom` globally by editing `jest.config.js`:
294+
295+
```diff title="jest.config.js"
296+
module.exports = {
297+
+ testEnvironment: 'jest-environment-jsdom',
298+
// ... other options ...
299+
}
300+
```
301+
302+
Or if you only need `jsdom` in some of your tests, you can enable it as and when
303+
needed using [docblocks](https://jestjs.io/docs/configuration#testenvironment-string):
304+
305+
```js
306+
/**
307+
* @jest-environment jsdom
308+
*/
309+
```
310+
290311
### Jest 24 (or lower) and defaults
291312

292313
If you're using the Jest testing framework version 24 or lower with the default
@@ -315,7 +336,7 @@ If you're running your tests in the browser bundled with webpack (or similar)
315336
then `React Testing Library` should work out of the box for you. However, most
316337
people using React Testing Library are using it with the Jest testing framework
317338
with the `testEnvironment` set to `jest-environment-jsdom` (which is the default
318-
configuration with Jest).
339+
configuration with Jest 26 and earlier).
319340

320341
`jsdom` is a pure JavaScript implementation of the DOM and browser APIs that
321342
runs in Node. If you're not using Jest and you would like to run your tests in

0 commit comments

Comments
 (0)