@@ -20,10 +20,11 @@ This module is distributed via [npm][npm] which is bundled with [node][node] and
20
20
should be installed as one of your project's ` devDependencies ` :
21
21
22
22
``` bash npm2yarn
23
- npm install --save-dev @noma.to/qwik-testing-library
23
+ npm install --save-dev @noma.to/qwik-testing-library @testing-library/dom
24
24
```
25
25
26
- This library supports ` qwik ` versions ` 1.7.2 ` and above.
26
+ This library supports ` qwik ` versions ` 1.7.2 ` and above and
27
+ ` @testing-library/dom ` versions ` 10.1.0 ` and above.
27
28
28
29
You may also be interested in installing ` @testing-library/jest-dom ` and
29
30
` @testing-library/user-event ` so you can use [ the custom jest
@@ -48,8 +49,8 @@ npm install --save-dev jsdom
48
49
49
50
## Vitest Configuration
50
51
51
- We recommend using ` @noma.to/qwik-testing-library ` with [ Vitest] [ ] as your test
52
- runner.
52
+ We recommend using ` @noma.to/qwik-testing-library ` with [ Vitest] [ vitest ] as your
53
+ test runner.
53
54
54
55
If you haven't done so already, add vitest to your project using Qwik CLI:
55
56
@@ -108,26 +109,31 @@ create it:
108
109
Then, create the ` vitest.setup.ts ` file:
109
110
110
111
``` ts title="vitest.setup.ts"
111
- import { afterEach } from ' vitest '
112
+ // Configure DOM matchers to work in Vitest
112
113
import ' @testing-library/jest-dom/vitest'
113
114
114
115
// This has to run before qdev.ts loads. `beforeAll` is too late
115
116
globalThis .qTest = false // Forces Qwik to run as if it was in a Browser
116
117
globalThis .qRuntimeQrl = true
117
118
globalThis .qDev = true
118
119
globalThis .qInspector = false
119
-
120
- afterEach (async () => {
121
- const {cleanup} = await import (' @noma.to/qwik-testing-library' )
122
- cleanup ()
123
- })
124
120
```
125
121
126
- This setup will make sure that Qwik is properly configured and that everything
127
- gets cleaned after each test.
122
+ This setup will make sure that Qwik is properly configured. It also loads
123
+ ` @testing-library/jest-dom/vitest ` in your test runner so you can use matchers
124
+ like ` expect(...).toBeInTheDocument() ` .
125
+
126
+ By default, Qwik Testing Library cleans everything up automatically for you. You
127
+ can opt out of this by setting the environment variable ` QTL_SKIP_AUTO_CLEANUP `
128
+ to ` true ` . Then in your tests, you can call the ` cleanup ` function when needed.
129
+ For example:
128
130
129
- Additionally, it loads ` @testing-library/jest-dom/vitest ` in your test runner so
130
- you can use matchers like ` expect(...).toBeInTheDocument() ` .
131
+ ``` ts
132
+ import {cleanup } from ' @noma.to/qwik-testing-library'
133
+ import {afterEach } from ' vitest'
134
+
135
+ afterEach (cleanup )
136
+ ```
131
137
132
138
Now, edit your ` tsconfig.json ` to declare the following global types:
133
139
0 commit comments