- Install libraries
npm install vitest jsdom @testing-library/react @testing-library/jest-dom @testing-library/user-event
- This stuff into the vite config file
export default defineConfig({
plugins: [react()],
test: {
globals: true,
environment: "jsdom",
setupFiles: "./src/test/setup.js",
},
})
- Create src/test/setup.js
import "@testing-library/jest-dom"
- Add 'test'-script to package.json
"test": "vitest"
- Write tests into './src/test' -directory
Filenames are like ComponentName.test.jsx