@@ -19,7 +19,7 @@ runner that's ESM compatible.
19
19
- [ ` @sveltejs/vite-plugin-svelte ` ] [ @sveltejs/vite-plugin-svelte ]
20
20
- [ ` vitest ` ] [ vitest ]
21
21
- [ ` jsdom ` ] [ jsdom ] , [ ` happy-dom ` ] [ happy-dom ] , or other [ Vitest DOM
22
- environment] [ ]
22
+ environment] [ vitest dom ]
23
23
24
24
``` bash npm2yarn
25
25
npm install --save-dev \
@@ -37,11 +37,10 @@ runner that's ESM compatible.
37
37
npm install --save-dev @vitest/ui
38
38
```
39
39
40
- 2 . Add a ` vitest-setup.js ` file to configure cleanup and
41
- [ ` @testing-library/jest-dom ` ] [ @testing-library/jest-dom ] , if using .
40
+ 2 . Add a ` vitest-setup.js ` file to optionally set up automatic post-test cleanup
41
+ and [ ` @testing-library/jest-dom ` ] [ @testing-library/jest-dom ] expect matchers .
42
42
43
- ``` ts
44
- // vitest-setup.js
43
+ ``` ts title="vitest-setup.js"
45
44
import ' @testing-library/svelte/vitest'
46
45
import ' @testing-library/jest-dom/vitest'
47
46
```
@@ -50,8 +49,7 @@ runner that's ESM compatible.
50
49
Svelte files, resolve browser exports during tests, use the [ jsdom] [ ] (or
51
50
[ happy-dom] [ ] ) environment, and run your setup file.
52
51
53
- ``` js
54
- // vitest.config.js
52
+ ``` js title="vitest.config.js"
55
53
import {defineConfig } from ' vitest/config'
56
54
import {svelte } from ' @sveltejs/vite-plugin-svelte'
57
55
@@ -77,9 +75,9 @@ runner that's ESM compatible.
77
75
alternative configuration options to ensure Svelte's browser bundle is used.
78
76
:::
79
77
80
- 4 . Add test scipts to your ` package.json ` to run the tests with Vitest
78
+ 4 . Add test scripts to your ` package.json ` to run the tests with Vitest
81
79
82
- ``` json
80
+ ``` json title="package.json"
83
81
{
84
82
"scripts" : {
85
83
"test" : " vitest run" ,
@@ -103,7 +101,7 @@ runner that's ESM compatible.
103
101
[ jsdom ] : https://github.com/jsdom/jsdom
104
102
[ happy-dom ] : https://github.com/capricorn86/happy-dom
105
103
[ @vitest/ui ] : https://vitest.dev/guide/ui.html
106
- [ vitest dom environment ] : https://vitest.dev/guide/environment.html
104
+ [ vitest dom ] : https://vitest.dev/guide/environment.html
107
105
[ testing-library/svelte-testing-library #222 ] :
108
106
https://github.com/testing-library/svelte-testing-library/issues/222
109
107
@@ -133,15 +131,13 @@ you must use Jest in [ESM mode][jest esm mode].
133
131
2 . Add a ` jest-setup.js ` file to configure
134
132
[ ` @testing-library/jest-dom ` ] [ @testing-library/jest-dom ] , if using.
135
133
136
- ``` ts
137
- // jest-setup.js
134
+ ``` ts title="jest-setup.js"
138
135
import ' @testing-library/jest-dom'
139
136
```
140
137
141
138
3 . Configure Jest to use jsdom, transform Svelte files, and use your setup file
142
139
143
- ``` js
144
- // jest.config.js
140
+ ``` js title="jest.config.js"
145
141
module .exports = {
146
142
" transform" : {
147
143
" ^.+\\ .svelte$" : " svelte-jester"
@@ -155,7 +151,7 @@ you must use Jest in [ESM mode][jest esm mode].
155
151
156
152
4 . Add the following to your ` package.json `
157
153
158
- ``` json
154
+ ``` json title="package.json"
159
155
{
160
156
"scripts" : {
161
157
"test" : " npx --node-options=\" --experimental-vm-modules\" jest src" ,
0 commit comments