Skip to content

Commit

Permalink
Added dont-cleanup-after-each.js setup utility
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeyper committed Oct 17, 2019
1 parent 016e960 commit bfc582d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
25 changes: 21 additions & 4 deletions docs/api-reference.md
Expand Up @@ -115,11 +115,28 @@ function cleanup: Promise<void>
Unmounts any rendered hooks rendered with `renderHook`, ensuring all effects have been flushed.

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

The `cleanup` function should be called after each test to ensure that previously rendered hooks
will not have any unintended side-effects on the following tests.

### Skipping Auto-Cleanup

Importing `@testing-library/react-hooks/dont-cleanup-after-each.js` in test setup files will disable
the auto-cleanup feature.

For example, in [Jest](https://jestjs.io/) this can be added to your
[Jest config](https://jestjs.io/docs/configuration):

```js
module.exports = {
setupFilesAfterEnv: [
'@testing-library/react-hooks/dont-cleanup-after-each.js'
// other setup files
]
}
```
Alternatively, setting the `RHTL_SKIP_AUTO_CLEANUP` environment variable to `true` before importing
`@testing-library/react-hooks` will also disable this feature.
1 change: 1 addition & 0 deletions dont-cleanup-after-each.js
@@ -0,0 +1 @@
process.env.RHTL_SKIP_AUTO_CLEANUP = true

0 comments on commit bfc582d

Please sign in to comment.