Skip to content

Commit 840d59f

Browse files
authored
Highlights necessary step in Svelte setup (#1330)
* Calls out globals in documentation * Restores comma * Formatting * Svelte cleanup docs match React language * Clarifies cleanup docs for Vue and Preact * Instructs user to call cleanup() themselves
1 parent 043e9cb commit 840d59f

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

docs/preact-testing-library/api.mdx

+6-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ const {results} = render(<YourComponent />, {options})
5252

5353
Unmounts 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
6063
import {render, cleanup} from '@testing-library/preact'

docs/react-testing-library/api.mdx

+3-4
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,9 @@ expect(firstRender).toMatchDiffSnapshot(asFragment())
289289
290290
Unmounts 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
297296
For example, if you're using the [ava](https://github.com/avajs/ava) testing
298297
framework, then you would need to use the `test.afterEach` hook like so:

docs/svelte-testing-library/api.mdx

+3-1
Original file line numberDiff line numberDiff 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
7577
Unmounts the component from the container and destroys the container.
7678

docs/svelte-testing-library/setup.mdx

+2-1
Original file line numberDiff line numberDiff 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'

docs/vue-testing-library/api.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ See a working example of `update` in the
232232
Unmounts 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
239239
Failing to call `cleanup` when you've called `render` could result in a memory
240240
leak and tests which are not idempotent (which can lead to difficult to debug

0 commit comments

Comments
 (0)