vitest
Use when working with Vitest for unit testing, component testing, snapshot testing, or mocking in Vite-based projects. Also use when migrating from Jest to Vitest, configuring Vitest workspaces, or using Vitest Browser Mode for component tests.
| Model | Source | Category |
|---|---|---|
| sonnet | core | Testing |
Full Reference
Vitest
Section titled “Vitest”Vitest v4.0.18 · Vite-native · ESM-first · Jest-compatible API
| Item | Value |
|---|---|
| Install | npm install -D vitest |
| Requires | Vite >= 6.0.0, Node >= 20.0.0 |
| Run | npx vitest (watch) · npx vitest run (once) |
| Coverage | npx vitest --coverage |
| UI | npx vitest --ui |
Reference Index
Section titled “Reference Index”Load the file that matches your task:
| Task | File |
|---|---|
| Install, config, environments | reference/setup-and-config.md |
| describe/it/test, lifecycle hooks, parameterized tests | reference/writing-tests.md |
| expect matchers, custom matchers, soft assertions | reference/assertions.md |
| vi.fn, vi.mock, vi.spyOn, module mocking | reference/mocking.md |
| toMatchSnapshot, inline snapshots, serializers | reference/snapshots.md |
| Fake timers, setSystemTime, async timers | reference/timers-and-dates.md |
| React/Vue component testing, Testing Library setup | reference/component-testing.md |
| Real browser testing, visual regression, traces | reference/browser-mode.md |
| v8/istanbul providers, thresholds, ignore comments | reference/coverage.md |
| projects config, monorepo, shared config | reference/monorepo-and-projects.md |
| TypeScript support, typed mocks, test.extend fixtures | reference/typescript.md |
| Watch mode, —changed, line filtering, UI mode | reference/watch-and-filtering.md |
| GitHub Actions, reporters, pool config | reference/ci-and-reporters.md |
| Migrating from Jest, API mapping, behavioral diffs | reference/jest-migration.md |
| v4.0 / v3.x breaking changes and new APIs | reference/changelog.md |
Common Mistakes
Section titled “Common Mistakes”| Mistake | Fix |
|---|---|
Using jest.fn() instead of vi.fn() | Import vi from vitest — all Jest globals map to vi.* |
mockReset() expected to return undefined | Vitest mockReset() restores the original implementation, not an empty function |
Using workspace config option | Removed in v4.0 — use projects in vitest.config.ts |
Missing coverage.include pattern | v4.0 requires explicit coverage.include for complete reports |
String browser provider (provider: 'playwright') | v4.0 requires factory: import { playwright } from '@vitest/browser-playwright' |
Importing from @vitest/browser/context | v4.0 moved to vitest/browser |
Using poolOptions or maxThreads/maxForks | v4.0: use top-level maxWorkers instead |