npmvitestv4.1.2
npmAdvanced

vitest

Next generation testing framework powered by Vite

testingvitejest-compatibleunit-teststypescriptvitesttestjest
The Problem

Jest works well but has a major friction point in Vite projects: Vite uses native ES modules and Vite-specific transforms (e.g. CSS modules, SVG imports), while Jest uses CommonJS and its own transform pipeline. Getting them to agree requires complex configuration. Vitest runs inside Vite's pipeline so your test environment matches your app environment exactly.

Mental Model

Vitest is Jest's API running inside Vite. If you know Jest (describe, it, expect, vi.mock), you know Vitest. The key difference is that Vitest uses Vite's config and transforms โ€” the same aliases, plugins, and module resolution in your tests as in your app. No separate babel or jest.config to maintain.

60-second start

Install vitest

npm install vitest
import { } from 'vitest';

Use it when

Use Vitest for any Vite-based project (React, Vue, Svelte) that needs unit or integration tests. It's also a good Jest replacement in non-Vite Node projects that want faster test execution and native ES module support.

Skip it when

For Next.js projects, Jest is still the recommended and better-documented choice. Vitest's browser mode (for running tests in a real browser) is still maturing โ€” for end-to-end browser tests, use Playwright or Cypress.

Alternatives
jestMore mature, larger ecosystem, recommended by React and Next.js โ€” use it for non-Vite projects
playwrightEnd-to-end browser testing โ€” tests run in real browsers, not jsdom; complementary to Vitest not a replacement
mochaOlder, more minimal test runner with no built-in assertions โ€” combine with chai; less common in modern projects

Ready to explore the full API?

See every class, function, and relationship in an interactive graph.