File tree Expand file tree Collapse file tree 5 files changed +17
-12
lines changed Expand file tree Collapse file tree 5 files changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -52,9 +52,12 @@ const {results} = render(<YourComponent />, {options})
5252
5353Unmounts the component from the container and destroys the container.
5454
55- 📝 When you import anything from the library, this automatically runs after each
56- test. If you'd like to disable this then set ` process.env.PTL_SKIP_AUTO_CLEANUP `
57- to true when running your tests.
55+ > This is called automatically if your testing framework (such as mocha, Jest or
56+ > Jasmine) injects a global ` afterEach() ` function into the testing environment.
57+ > If not, you will need to call ` cleanup() ` after each test.
58+
59+ If you'd like to disable this then set ` process.env.PTL_SKIP_AUTO_CLEANUP ` to
60+ true when running your tests.
5861
5962``` jsx
6063import {render , cleanup } from ' @testing-library/preact'
Original file line number Diff line number Diff line change @@ -289,10 +289,9 @@ expect(firstRender).toMatchDiffSnapshot(asFragment())
289289
290290Unmounts React trees that were mounted with [render](#render).
291291
292- > Please note that this is done automatically if the testing framework you're
293- > using supports the ` afterEach ` global and it is injected to your testing
294- > environment (like mocha, Jest, and Jasmine). If not, you will need to do
295- > manual cleanups after each test.
292+ > This is called automatically if your testing framework (such as mocha, Jest or
293+ > Jasmine) injects a global ` afterEach ()` function into the testing environment.
294+ > If not, you will need to call ` cleanup ()` after each test.
296295
297296For example, if you're using the [ava](https://github.com/avajs/ava) testing
298297framework, then you would need to use the ` test .afterEach ` hook like so:
Original file line number Diff line number Diff line change @@ -70,7 +70,9 @@ const {results} = render(YourComponent, {myProp: 'value'})
7070
7171## ` cleanup `
7272
73- > You don't need to import or use this, it's done automagically for you!
73+ > This is called automatically if your testing framework (such as mocha, Jest or
74+ > Jasmine) injects a global ` afterEach() ` function into the testing environment.
75+ > If not, you will need to call ` cleanup() ` after each test.
7476
7577Unmounts the component from the container and destroys the container.
7678
Original file line number Diff line number Diff line change @@ -46,7 +46,8 @@ npm install --save-dev @vitest/ui
4646 npm install --save-dev @sveltejs/vite-plugin-svelte vite
4747 ```
4848
49- 3 . Add a ` vitest.config.ts ` configuration file to the root of your project
49+ 3 . Add a ` vitest.config.ts ` configuration file to the root of your project. Add
50+ ` globals: true ` so ` cleanup() ` runs after each test.
5051
5152 ``` js
5253 import {defineConfig } from ' vitest/config'
Original file line number Diff line number Diff line change @@ -232,9 +232,9 @@ See a working example of `update` in the
232232Unmounts Vue trees that were mounted with
233233[ render] ( #rendercomponent-options-callback ) .
234234
235- > If you are using an environment that supports ` afterEach ` hook ( as in Jest),
236- > there's no need to call ` cleanup ` manually. Vue Testing Library handles it for
237- > you.
235+ > This is called automatically if your testing framework (such as mocha, Jest or
236+ > Jasmine) injects a global ` afterEach() ` function into the testing environment.
237+ > If not, you will need to call ` cleanup() ` after each test .
238238
239239Failing to call ` cleanup ` when you've called ` render ` could result in a memory
240240leak and tests which are not idempotent (which can lead to difficult to debug
You can’t perform that action at this time.
0 commit comments