File tree Expand file tree Collapse file tree 1 file changed +34
-2
lines changed
docs/react-testing-library Expand file tree Collapse file tree 1 file changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -513,6 +513,38 @@ mocha --require ./mocha-watch-cleanup-after-each.js
513513
514514### Auto Cleanup in Vitest
515515
516- If you're using Vitest and want automatic cleanup to work, you need to
516+ If you're using Vitest and want automatic cleanup to work, you can
517517[ enable globals] ( https://vitest.dev/config/#globals ) through its configuration
518- file.
518+ file:
519+
520+ ``` ts title="vitest.config.ts"
521+ import {defineConfig } from ' vitest/config'
522+
523+ export default defineConfig ({
524+ test: {
525+ globals: true ,
526+ },
527+ })
528+ ```
529+
530+ If you don't want to enable globals, you can import ` cleanup ` and call it
531+ manually in a top-level ` afterEach ` hook:
532+
533+ ``` ts title="vitest.config.ts"
534+ import {defineConfig } from ' vitest/config'
535+
536+ export default defineConfig ({
537+ test: {
538+ setupFiles: [' vitest-cleanup-after-each.ts' ],
539+ },
540+ })
541+ ```
542+
543+ ``` ts title="vitest-cleanup-after-each.ts"
544+ import {cleanup } from ' @testing-library/react'
545+ import {afterEach } from ' vitest'
546+
547+ afterEach (() => {
548+ cleanup ()
549+ })
550+ ```
You can’t perform that action at this time.
0 commit comments