Skip to content

Highlights necessary step in Svelte setup #1330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions docs/preact-testing-library/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ const {results} = render(<YourComponent />, {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'
Expand Down
7 changes: 3 additions & 4 deletions docs/react-testing-library/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion docs/svelte-testing-library/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 2 additions & 1 deletion docs/svelte-testing-library/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions docs/vue-testing-library/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down