File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
docs/react-testing-library Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -510,3 +510,41 @@ And register it using mocha's `-r` flag:
510510```
511511mocha --require ./mocha-watch-cleanup-after-each.js
512512```
513+
514+ ### Auto Cleanup in Vitest
515+
516+ If you're using Vitest and want automatic cleanup to work, you can
517+ [ enable globals] ( https://vitest.dev/config/#globals ) through its configuration
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