Skip to content

Commit bfc582d

Browse files
committed
Added dont-cleanup-after-each.js setup utility
1 parent 016e960 commit bfc582d

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

Diff for: docs/api-reference.md

+21-4
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,28 @@ function cleanup: Promise<void>
115115
Unmounts any rendered hooks rendered with `renderHook`, ensuring all effects have been flushed.
116116

117117
> Please note that this is done automatically if the testing framework you're using supports the
118-
> `afterEach` global (like mocha, Jest, and Jasmine). If not, you will need to do manual cleanups
118+
> `afterEach` global (like Jest, mocha and Jasmine). If not, you will need to do manual cleanups
119119
> after each test.
120-
>
121-
> Setting the `RHTL_SKIP_AUTO_CLEANUP` environment variable to `true` before the
122-
> `@testing-library/react-hooks` is imported will disable this feature.
123120

124121
The `cleanup` function should be called after each test to ensure that previously rendered hooks
125122
will not have any unintended side-effects on the following tests.
123+
124+
### Skipping Auto-Cleanup
125+
126+
Importing `@testing-library/react-hooks/dont-cleanup-after-each.js` in test setup files will disable
127+
the auto-cleanup feature.
128+
129+
For example, in [Jest](https://jestjs.io/) this can be added to your
130+
[Jest config](https://jestjs.io/docs/configuration):
131+
132+
```js
133+
module.exports = {
134+
setupFilesAfterEnv: [
135+
'@testing-library/react-hooks/dont-cleanup-after-each.js'
136+
// other setup files
137+
]
138+
}
139+
```
140+
141+
Alternatively, setting the `RHTL_SKIP_AUTO_CLEANUP` environment variable to `true` before importing
142+
`@testing-library/react-hooks` will also disable this feature.

Diff for: dont-cleanup-after-each.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
process.env.RHTL_SKIP_AUTO_CLEANUP = true

0 commit comments

Comments
 (0)