File tree 5 files changed +17
-12
lines changed
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})
52
52
53
53
Unmounts the component from the container and destroys the container.
54
54
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.
58
61
59
62
``` jsx
60
63
import {render , cleanup } from ' @testing-library/preact'
Original file line number Diff line number Diff line change @@ -289,10 +289,9 @@ expect(firstRender).toMatchDiffSnapshot(asFragment())
289
289
290
290
Unmounts React trees that were mounted with [render](#render).
291
291
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.
296
295
297
296
For example, if you're using the [ava](https://github.com/avajs/ava) testing
298
297
framework, 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'})
70
70
71
71
## ` cleanup `
72
72
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.
74
76
75
77
Unmounts the component from the container and destroys the container.
76
78
Original file line number Diff line number Diff line change @@ -46,7 +46,8 @@ npm install --save-dev @vitest/ui
46
46
npm install --save-dev @sveltejs/vite-plugin-svelte vite
47
47
```
48
48
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.
50
51
51
52
``` js
52
53
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
232
232
Unmounts Vue trees that were mounted with
233
233
[ render] ( #rendercomponent-options-callback ) .
234
234
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 .
238
238
239
239
Failing to call ` cleanup ` when you've called ` render ` could result in a memory
240
240
leak 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