Skip to content

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.

ModelSourceCategory
sonnetcoreTesting
Full Reference

Vitest v4.0.18 · Vite-native · ESM-first · Jest-compatible API

ItemValue
Installnpm install -D vitest
RequiresVite >= 6.0.0, Node >= 20.0.0
Runnpx vitest (watch) · npx vitest run (once)
Coveragenpx vitest --coverage
UInpx vitest --ui

Load the file that matches your task:

TaskFile
Install, config, environmentsreference/setup-and-config.md
describe/it/test, lifecycle hooks, parameterized testsreference/writing-tests.md
expect matchers, custom matchers, soft assertionsreference/assertions.md
vi.fn, vi.mock, vi.spyOn, module mockingreference/mocking.md
toMatchSnapshot, inline snapshots, serializersreference/snapshots.md
Fake timers, setSystemTime, async timersreference/timers-and-dates.md
React/Vue component testing, Testing Library setupreference/component-testing.md
Real browser testing, visual regression, tracesreference/browser-mode.md
v8/istanbul providers, thresholds, ignore commentsreference/coverage.md
projects config, monorepo, shared configreference/monorepo-and-projects.md
TypeScript support, typed mocks, test.extend fixturesreference/typescript.md
Watch mode, —changed, line filtering, UI modereference/watch-and-filtering.md
GitHub Actions, reporters, pool configreference/ci-and-reporters.md
Migrating from Jest, API mapping, behavioral diffsreference/jest-migration.md
v4.0 / v3.x breaking changes and new APIsreference/changelog.md
MistakeFix
Using jest.fn() instead of vi.fn()Import vi from vitest — all Jest globals map to vi.*
mockReset() expected to return undefinedVitest mockReset() restores the original implementation, not an empty function
Using workspace config optionRemoved in v4.0 — use projects in vitest.config.ts
Missing coverage.include patternv4.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/contextv4.0 moved to vitest/browser
Using poolOptions or maxThreads/maxForksv4.0: use top-level maxWorkers instead