diff --git a/docs/preact-testing-library/api.mdx b/docs/preact-testing-library/api.mdx index ca4d8691f..18dd43131 100644 --- a/docs/preact-testing-library/api.mdx +++ b/docs/preact-testing-library/api.mdx @@ -52,9 +52,12 @@ const {results} = render(, {options}) Unmounts the component from the container and destroys the container. -📝 When you import anything from the library, this automatically runs after each -test. If you'd like to disable this then set `process.env.PTL_SKIP_AUTO_CLEANUP` -to true when running your tests. +> This is called automatically if your testing framework (such as mocha, Jest or +> Jasmine) injects a global `afterEach()` function into the testing environment. +> If not, you will need to call `cleanup()` after each test. + +If you'd like to disable this then set `process.env.PTL_SKIP_AUTO_CLEANUP` to +true when running your tests. ```jsx import {render, cleanup} from '@testing-library/preact' diff --git a/docs/react-testing-library/api.mdx b/docs/react-testing-library/api.mdx index 6150b6418..366a56f9f 100644 --- a/docs/react-testing-library/api.mdx +++ b/docs/react-testing-library/api.mdx @@ -289,10 +289,9 @@ expect(firstRender).toMatchDiffSnapshot(asFragment()) Unmounts React trees that were mounted with [render](#render). -> Please note that this is done automatically if the testing framework you're -> using supports the `afterEach` global and it is injected to your testing -> environment (like mocha, Jest, and Jasmine). If not, you will need to do -> manual cleanups after each test. +> This is called automatically if your testing framework (such as mocha, Jest or +> Jasmine) injects a global `afterEach()` function into the testing environment. +> If not, you will need to call `cleanup()` after each test. For example, if you're using the [ava](https://github.com/avajs/ava) testing framework, then you would need to use the `test.afterEach` hook like so: diff --git a/docs/svelte-testing-library/api.mdx b/docs/svelte-testing-library/api.mdx index 7af1ac643..c0171dd21 100644 --- a/docs/svelte-testing-library/api.mdx +++ b/docs/svelte-testing-library/api.mdx @@ -70,7 +70,9 @@ const {results} = render(YourComponent, {myProp: 'value'}) ## `cleanup` -> You don't need to import or use this, it's done automagically for you! +> This is called automatically if your testing framework (such as mocha, Jest or +> Jasmine) injects a global `afterEach()` function into the testing environment. +> If not, you will need to call `cleanup()` after each test. Unmounts the component from the container and destroys the container. diff --git a/docs/svelte-testing-library/setup.mdx b/docs/svelte-testing-library/setup.mdx index d5bac8768..2bfcb7f7c 100644 --- a/docs/svelte-testing-library/setup.mdx +++ b/docs/svelte-testing-library/setup.mdx @@ -46,7 +46,8 @@ npm install --save-dev @vitest/ui npm install --save-dev @sveltejs/vite-plugin-svelte vite ``` -3. Add a `vitest.config.ts` configuration file to the root of your project +3. Add a `vitest.config.ts` configuration file to the root of your project. Add + `globals: true` so `cleanup()` runs after each test. ```js import {defineConfig} from 'vitest/config' diff --git a/docs/vue-testing-library/api.mdx b/docs/vue-testing-library/api.mdx index 3bac572ba..fc5cc4a17 100644 --- a/docs/vue-testing-library/api.mdx +++ b/docs/vue-testing-library/api.mdx @@ -232,9 +232,9 @@ See a working example of `update` in the Unmounts Vue trees that were mounted with [render](#rendercomponent-options-callback). -> If you are using an environment that supports `afterEach` hook (as in Jest), -> there's no need to call `cleanup` manually. Vue Testing Library handles it for -> you. +> This is called automatically if your testing framework (such as mocha, Jest or +> Jasmine) injects a global `afterEach()` function into the testing environment. +> If not, you will need to call `cleanup()` after each test. Failing to call `cleanup` when you've called `render` could result in a memory leak and tests which are not idempotent (which can lead to difficult to debug