Skip to content

Commit 4bd9eb4

Browse files
authored
Updated jest v27 instructions to v28 (testing-library#1061)
1 parent e1a17a7 commit 4bd9eb4

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

docs/react-testing-library/setup.mdx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,34 @@ using Create React App without TypeScript, save this to `jsconfig.json` instead.
285285
}
286286
```
287287

288+
### Jest 28
289+
290+
If you're using Jest 28 or later, jest-environment-jsdom package now must be installed separately.
291+
```
292+
npm install --save-dev jest-environment-jsdom
293+
```
294+
295+
`jsdom` is also no longer the default environment. You can enable `jsdom` globally by editing `jest.config.js`:
296+
297+
```diff title="jest.config.js"
298+
module.exports = {
299+
+ testEnvironment: 'jsdom',
300+
// ... other options ...
301+
}
302+
```
303+
304+
Or if you only need `jsdom` in some of your tests, you can enable it as and when needed using
305+
[docblocks](https://jestjs.io/docs/configuration#testenvironment-string):
306+
307+
```js
308+
/**
309+
* @jest-environment jsdom
310+
*/
311+
```
312+
288313
### Jest 27
289314

290-
If you're using a recent version of Jest (27 or later), `jsdom` is no longer the
291-
default environment. You can enable `jsdom` globally by editing
292-
`jest.config.js`:
315+
If you're using a recent version of Jest (27), `jsdom` is no longer the default environment. You can enable `jsdom` globally by editing `jest.config.js`:
293316

294317
```diff title="jest.config.js"
295318
module.exports = {

0 commit comments

Comments
 (0)