@@ -99,7 +99,72 @@ with any testing framework and runner you're comfortable with.
9999 ```
100100 npm run test
101101 ```
102+ ## Vitest
103+ 1 . Install Vitest and jsdom
102104
105+ ```
106+ npm install --save-dev vitest jsdom
107+ ```
108+
109+ 2 . Add the following to your ` package.json `
110+
111+ ``` json
112+ {
113+ "scripts" : {
114+ "test" : " vitest run src" ,
115+ "test:watch" : " vitest src"
116+ }
117+ }
118+ ```
119+
120+ 3 . You'll need to compile the Svelte components before using them in Vitest, so
121+ you need to install
122+ [ @sveltejs/vite-plugin-svelte ] ( https://github.com/sveltejs/vite-plugin-svelte ) and Vite
123+
124+
125+ ```
126+ npm install --save-dev @sveltejs/vite-plugin-svelte vite
127+ ```
128+
129+ 4 . Add a ` vitest.config.ts ` configuration file to the root of your project
130+
131+ ``` js
132+ import { defineConfig } from ' vite' ;
133+ import { svelte } from ' @sveltejs/vite-plugin-svelte' ;
134+
135+ export default defineConfig ({
136+ plugins: [svelte ({ hot: ! process .env .VITEST })],
137+ test: {
138+ include: [' src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}' ],
139+ globals: true ,
140+ environment: ' jsdom'
141+ }
142+ });
143+
144+ ```
145+
146+ 5 . This is optional but it is recommended, you can install
147+ [ jest-dom] ( https://github.com/testing-library/jest-dom ) to add handy
148+ assertions to Jest
149+
150+ 5.1 Install ` jest-dom `
151+
152+ ```
153+ npm install --save-dev @testing-library/jest-dom
154+ ```
155+
156+ 5.2 import ` @testing-library/jest-dom ` at the start of your test files
157+
158+ ``` js
159+ import ' @testing-library/jest-dom' ;
160+ ```
161+
162+ 6 . Create your component and a test file (checkout the rest of the docs to see how)
163+ and run the following command to run the tests.
164+
165+ ```
166+ npm run test
167+ ```
103168## Typescript
104169
105170To use Typescript, you'll need to install and configure ` svelte-preprocess ` and
0 commit comments