Skip to main content

Vitest

What is Vitestโ€‹

Vitest is a testing framework powered by Vite. It is MIT licensed and currently at version 4.x. With ~34.4M weekly npm downloads and ~16.2k GitHub stars, it is the recommended testing framework for Vite-based projects, offering a Jest-compatible API with dramatically faster execution.

Why we recommend itโ€‹

  • Vite-native โ€” shares your vite.config.ts, so TypeScript, JSX, CSS modules, and path aliases work instantly with zero duplicate configuration.
  • Jest-compatible API โ€” describe, it, expect, mocking, and snapshots all work the same way. Migration from Jest is straightforward.
  • Smart watch mode โ€” only re-runs tests affected by changed files. Combined with Vite's transform pipeline, the feedback loop is near-instant.
  • Built-in coverage and UI โ€” --coverage with V8 or Istanbul, plus a browser-based test UI for exploring results. No extra packages needed.
  • Browser mode โ€” run tests in real browser environments when jsdom isn't enough, without switching to a separate E2E tool.

When to useโ€‹

  • Unit and integration tests in any Vite-based project
  • Projects using React + TypeScript โ€” component testing with React Testing Library works out of the box
  • Migrating away from Jest in a Vite project โ€” the API compatibility makes it near drop-in
  • In-source testing during rapid prototyping (tests co-located in production files, stripped at build time)

When NOT to useโ€‹

  • End-to-end testing โ€” use Playwright or Cypress for full browser automation, user flows, and cross-browser checks
  • Non-Vite projects with deep webpack integration โ€” Jest may still be the path of least resistance
note

Vitest covers unit, integration, and component-level visual regression tests (via browser mode โ€” see the Visual Regression Testing with Vitest recipe). For end-to-end testing (user flows, cross-browser compatibility), pair it with Playwright or Cypress.

Resourcesโ€‹