Skip to content

Commit

Permalink
Documented the cleanup and auto-cleanup functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeyper committed Oct 13, 2019
1 parent 183c3ce commit ba02be0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/api-reference.md
Expand Up @@ -9,6 +9,7 @@ route: '/reference/api'

- [`renderHook`](/reference/api#renderhook)
- [`act`](/reference/api#act)
- [`cleanup`](/reference/api#cleanup)

---

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

This is the same [`act` function](https://reactjs.org/docs/test-utils.html#act) that is exported by
`react-test-renderer`.

---

## `cleanup`

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
> 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.

```js
async function cleanup: void
```

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.

0 comments on commit ba02be0

Please sign in to comment.