Build and Test JavaScript with Confidence Using Vitest

Vitest is a fast unit test runner built on Vite. It understands TypeScript, ESM and your existing Vite config out of the box, and ships Jest-compatible APIs, snapshots, mocking, coverage and a browser dashboard.

  • Node.js 22.12+
  • Vite 6.4 / 7 / 8
  • TypeScript & ESM native
  • MIT license

What Is Vitest

Vitest is an open-source testing framework that uses Vite to run your tests with the same plugins, import aliases and TypeScript settings as your application.

Write tests with familiar APIs such as describe, expect and vi.fn(). Watch mode reruns tests affected by the files you edit. For browser-specific behaviour, run your tests in a real browser or inspect results in Vitest UI.

A green testing core connected to surrounding test modules
Current majorVitest 5 (released September 3, 2026)
Repositorygithub.com/vitest-dev/vitest, main branch
LicenseMIT — free for personal and commercial use
EcosystemVue, React, Svelte, Angular CLI, Next.js and more

Features of Vitest

Ten capabilities that matter day to day, from the transform pipeline to the browser dashboard.

Vite-powered transforms

Tests use the same Vite config, plugins and aliases as the app, so TypeScript, JSX, Vue SFCs and Svelte components need no separate transpiler setup.

Smart watch mode

Vitest tracks the module graph and reruns only the test files that import the changed module, keeping feedback tight while you edit.

Jest-compatible API

describe, it, expect, vi.fn, vi.mock, fake timers and snapshots follow familiar names, which makes most Jest suites portable with small edits.

Mocking with vi.when

Vitest 5 adds vi.when for per-argument spy behaviour, plus toHaveBeenExhausted to assert that every planned response was used.

Coverage providers

Choose the v8 provider or Istanbul, enforce global or per-file thresholds and export text, HTML, JSON or lcov reports from one flag.

Browser Mode with Trace View

Run component tests in a real browser via Playwright or WebdriverIO. Trace View records interactions and assertions as DOM snapshots you can replay.

Vitest UI

The optional @vitest/ui package opens a browser dashboard to filter suites, rerun files, inspect console output and browse the module graph.

Projects and nesting

Define multiple projects in one config, each with its own environment. Inline projects inherit the root config, and the -p filter respects nesting.

Benchmarks and flaky-test tools

bench is a test-context fixture in Vitest 5, with baseline comparison, and --repeats runs a test several times to expose flaky behaviour.

Snapshots and in-source tests

Inline, file and custom-serialiser snapshots are built in, and import.meta.vitest lets small utilities keep their tests next to the implementation.

How It Works

Install Vitest, write a test and run it locally or in CI.

Vitest logovitest
  1. 01

    Install the package

    Run npm install -D vitest in a project that has Node.js 22.12 or newer. Vite is installed as a peer dependency when it is not already present.

  2. 02

    Configure (optional)

    Add a test block to vite.config.ts or create vitest.config.ts to set the environment, globals, setup files, coverage and projects.

  3. 03

    Write a test

    Create sum.test.ts, import test and expect from vitest, and assert the behaviour of your function or component.

  4. 04

    Run and iterate

    Start npx vitest for watch mode or vitest run for a single pass. Add --ui or --coverage when you need them.

Compatibility and Requirements

Requirements below come from the Vitest 5 release notes and the package manifest on the main branch. Nothing here is estimated.

Node.js runtime

22.12+, 24.x, 26+

Required

Vite

6.4, 7.x or 8.x

Peer dependency

Operating systems

Windows, macOS, Linux

Wherever Node runs

Browser Mode

Playwright, WebdriverIO, preview

Optional provider

Package managers

npm, pnpm, yarn, bun

Any of them

Frameworks

Vue, React, Svelte, Solid, Angular, Next.js

Via Vite plugins or builders

DOM environments

jsdom, happy-dom

Install separately

Languages

TypeScript, JavaScript, JSX/TSX, ESM, CJS

Built in
Version lines at a glance
MajorReleasedMinimum Node.jsVite rangeStatus
Vitest 5September 3, 202622.126.4 – 8.xCurrent major
Vitest 4October 22, 2025 (4.1 on March 12, 2026)20.x6 – 7.x (4.1 adds Vite 8)Previous major, latest minor receives fixes
Vitest 3January 17, 202518.x5 – 6.xNo longer supported

Use Cases

Typical scenarios the runner is designed for.

Unit testing utilities

Pure functions, parsers, validators and stores get instant feedback in watch mode with no DOM overhead.

Component tests

Render Vue, React, Svelte or Solid components in jsdom or a real browser and assert on the DOM with Testing Library.

Monorepos and workspaces

Use projects to give each package its own environment and setup while sharing one root config and one command.

API and integration tests

Spin up handlers, mock fetch with vi.mock or MSW, and test routes alongside the code that defines them.

Continuous integration

vitest run with the junit or json reporter, coverage thresholds and --merge-reports fits GitHub Actions, GitLab CI and others.

Performance benchmarks

The bench fixture compares implementations and stores baselines so regressions show up in the same run as the tests.

Benefits of Vitest

Vitest is not only about raw speed. Its value is removing an entire second toolchain from the project and giving every failure a place where it can be understood.

Download Now
  • One pipeline, no duplicate config

    Aliases, env variables and plugins defined for the app apply to tests automatically.

  • Fast feedback while editing

    Module-graph-aware reruns mean a save usually triggers only a handful of test files.

  • Low migration cost

    Jest-style APIs keep existing knowledge and most existing tests useful.

  • First-class TypeScript

    Type-check mode, typed fixtures and expectTypeOf make types part of the test suite.

  • Clear tooling

    UI dashboard, HTML reporter and Trace View turn failures into something you can inspect.

  • Active ecosystem

    Framework docs for Angular, Next.js, Nuxt, SvelteKit and others document a Vitest path.

Install Vitest

Pick the route that matches your project. Each one ends with a passing test.

  1. Step 1

    Install

    npm install -D vitest (or pnpm add -D vitest, yarn add -D vitest, bun add -d vitest).

  2. Step 2

    Add the script

    In package.json set "test": "vitest". CI pipelines should call vitest run instead.

  3. Step 3

    Write a first test

    Create src/sum.test.ts importing test and expect from vitest.

  4. Step 4

    Run

    Execute npm test. Watch mode starts, reruns on save and prints pass/fail per file.

Green download arrow above an amber source archive

Download Vitest

The button fetches main.zip straight from the official GitHub repository: the complete Vitest monorepo including the core package, UI, browser mode, coverage providers, docs and examples. It is source code, not an installer. To add Vitest to a project, use the npm command from the setup section; use this archive to read, build or contribute to the code.

  • Package version on main5.1.0 (package.json when checked)
  • SourceGitHub, vitest-dev/vitest, main branch
  • LicenseMIT
  • Archive typeZIP of the full monorepo source
Download Vitest

Download and Setup Practices

Practical guidance, not marketing claims.

Use the official source

The link above goes to github.com/vitest-dev. Avoid re-packaged downloads from unknown sites; the package on npm is the normal install path.

Check what you installed

Run npm ls vitest to confirm the version and npm audit to review advisories in your dependency tree.

Mind test permissions

Tests run with your user's rights. Keep file-system and network side effects inside temporary folders and mocked clients.

Back up snapshots and config

Commit __snapshots__ and the config file so a bad update can be rolled back with your version control.

Keep it updated

Patch releases ship frequently. Read the migration guide before moving between majors, especially from 4 to 5.

Pros and Cons

Strengths and the limitations you should know before adopting it.

Pros

  • Reuses the Vite config, plugins and aliases already in the project
  • Jest-compatible API lowers migration effort
  • Watch mode reruns only affected tests
  • TypeScript, ESM and JSX work without extra transpiler setup
  • UI dashboard, HTML reporter and Trace View for debugging
  • MIT-licensed with frequent patch releases

Cons

  • Requires Node.js 22.12+ and Vite 6.4+ in version 5
  • Async React Server Components are not supported in Next.js unit tests
  • Browser Mode needs a separate provider package and a browser
  • Major upgrades change defaults such as clearMocks and strict locators
  • The main.zip download is source code, not a ready-to-run binary

Troubleshooting

Six issues that account for most first-week questions.

Unsupported engine warning

npm reports EBADENGINE or Vitest exits immediately. Update to Node.js 22.12 or newer; check with node -v and use nvm or fnm to switch.

Vite peer dependency conflict

ERESOLVE during install usually means an old Vite pin. Vitest 5 wants Vite 6.4+; update Vite or install the Vitest major that matches your Vite.

document is not defined

The default environment is Node. Install jsdom or happy-dom and set test.environment, or add a @vitest-environment comment to the file.

Tests hang or never exit

Plain vitest is watch mode. Use vitest run in CI, and close open handles such as servers and timers in afterAll.

Mocks leak or counts look wrong

Vitest 5 clears mock history before each test. Assert within the test that made the calls, or set clearMocks: false to keep the old behaviour.

Stale results after config changes

Restart the watcher after editing vite.config or vitest.config. If the on-disk module cache looks stale, clear the .vitest directory and rerun.

Frequently Asked Questions

Twenty answers in two groups. Open one at a time.