Skip to content

Commit ba02be0

Browse files
committed
Documented the cleanup and auto-cleanup functionality
1 parent 183c3ce commit ba02be0

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

docs/api-reference.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ route: '/reference/api'
99

1010
- [`renderHook`](/reference/api#renderhook)
1111
- [`act`](/reference/api#act)
12+
- [`cleanup`](/reference/api#cleanup)
1213

1314
---
1415

@@ -102,3 +103,23 @@ A function to unmount the test component. This is commonly used to trigger clean
102103

103104
This is the same [`act` function](https://reactjs.org/docs/test-utils.html#act) that is exported by
104105
`react-test-renderer`.
106+
107+
---
108+
109+
## `cleanup`
110+
111+
Unmounts any rendered hooks rendered with `renderHook`, ensuring all effects have been flushed.
112+
113+
> Please note that this is done automatically if the testing framework you're using supports the
114+
> `afterEach` global (like mocha, Jest, and Jasmine). If not, you will need to do manual cleanups
115+
> after each test.
116+
>
117+
> Setting the `RHTL_SKIP_AUTO_CLEANUP` environment variable to `true` before the
118+
> `@testing-library/react-hooks` is imported will disable this feature.
119+
120+
```js
121+
async function cleanup: void
122+
```
123+
124+
The `cleanup` function should be called after each test to ensure that previously rendered hooks
125+
will not have any unintended side-effects on the following tests.

0 commit comments

Comments
 (0)