Skip to content

Commit 90eb946

Browse files
committed
docs: add global cleanup instructions
1 parent f676d96 commit 90eb946

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,22 @@ Unmounts any React trees that were mounted with [renderHook](#renderhookcallback
148148

149149
This is the same [`cleanup` function](https://testing-library.com/docs/react-testing-library/api#cleanup) that is exported by `react-testing-library`.
150150

151+
Optionally, it is possible to import `cleanup` in a global test file. Using that way, it isn't necessary to run `afterEach(cleanup)` on every test script.
152+
153+
```js
154+
// in package.json
155+
"jest": {
156+
// ...
157+
// use this if Jest version < 24
158+
"setupTestFrameworkScriptFile": "<rootDir>/src/setupTests.js",
159+
// or if Jest version >= 24
160+
"setupFilesAfterEnv": ["<rootDir>/src/setupTests.js"],
161+
}
162+
163+
// src/setupTests.js
164+
import 'react-hooks-testing-library/cleanup-after-each';
165+
```
166+
151167
### `act(callback)`
152168

153169
This is the same [`act` function](https://testing-library.com/docs/react-testing-library/api#act) that is exported by `react-testing-library`.

0 commit comments

Comments
 (0)