Vitest is a Vite-powered test runner that needs Vite 6.4+ and Node 22.12+. Setup, a first test, shared config, Vitest vs Jest and a Jest migration table.
Vitest is a test framework powered by Vite. It needs Vite 6.4.0 or newer and Node.js 22.12.0 or newer, installs with npm install -D vitest, and reads your existing vite.config.* so tests share the app's plugins.[1] The verdict against Jest: if your app already builds with Vite, pick Vitest, because its docs call a second test pipeline "not justifiable".[3] Jest's own docs say it is not supported by Vite.[7] Stay on Jest when a webpack or Babel setup works and you have no reason to touch it. Below: setup, a first test, shared config, the comparison table, migration steps and what breaks.
What Vitest is and what it needs
The docs describe Vitest (pronounced "veetest") as a next generation testing framework powered by Vite.[1] The project's pitch is a test runner that uses the same configuration as your app, so dev, build and test share one transformation pipeline.[4]
Check the runtime before anything else. The requirement is hard, not a suggestion: Vitest 5.0 does not support older Vite or Node.js versions and "may" produce unexpected errors on them.[10] The GitHub releases page marked v5.1.2 as the latest release, published November 25, 2026, with a v5.2.0-beta.1 pre-release dated November 30.[9]
| Requirement | Value |
|---|---|
| Vite | >= 6.4.0[1] |
| Node.js | >= 22.12.0[1] |
| Test file names | Must contain .test. or .spec. by default[1] |
| Yarn | Run yarn add -D vite too. Vite is a required peer dependency and Yarn does not install peers[10] |
| Default environment | node. jsdom, happy-dom and edge-runtime are options[6] |
Install Vitest and run a first test
Install it as a dev dependency. The docs recommend a local copy in package.json over running it ad hoc with npx vitest, and they suggest adding the .vitest/ directory, where Vitest stores generated artifacts, to .gitignore.[1]
npm install -D vitest
# .gitignore
# Vitest reports and artifacts
.vitest/The getting-started test is a function that adds two numbers.[1] Note the explicit import from vitest. Globals are off by default, a difference that matters later.
// sum.js
export function sum(a, b) {
return a + b
}
// sum.test.js
import { expect, test } from 'vitest'
import { sum } from './sum.js'
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3)
})Add "test": "vitest" to the scripts section of package.json and run npm run test. That starts watch mode, which Vitest enables by default.[1][4] For a single pass, as in CI, use vitest run. It also accepts flags such as --reporter and --coverage.[1]
One trap for Bun users: use bun run test, not bun test. The second command launches Bun's own test runner, not Vitest.[1]
Share config with vite.config
This is the real reason to choose Vitest. It reads vite.config.* by default, so existing Vite plugins and configuration work without a second setup. For test-only settings you can add a dedicated vitest.config.*.[1] The test options live under a test key, and defineConfig comes from vitest/config.[5]
// vitest.config.ts
import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
test: {
globals: true,
environment: 'jsdom',
},
})The react() plugin line mirrors a plugin example on the migration page; globals and environment are documented config options.[5][6][10] If you set globals: true and use TypeScript, add vitest/globals to compilerOptions.types in tsconfig.json. If you set environment: 'jsdom', vitest/jsdom is the types entry for the jsdom global.[5][6] To change the environment for one file only, put a @vitest-environment docblock or comment at the top. For compatibility, @jest-environment is accepted too.[6]
Vitest vs Jest
The two share an API shape (it, expect, snapshots, mocks, coverage), so the choice comes down to the pipeline underneath.[3] Vitest's comparison page says it is a drop-in replacement for Jest in most projects, and that is the project's claim about its own tool.[3]
| Area | Vitest | Jest |
|---|---|---|
| Transform pipeline | Vite transforms files, shared with dev and build[4] | Its own pipeline. babel-jest transforms files automatically when a Babel config exists, or you pick a transformer such as ts-jest[7] |
| Vite support | Built for Vite from the start[4] | Docs: "not supported by Vite"; vite-jest does not work with Vite after 2.4.2[7] |
| TypeScript | Handled by the Vite pipeline[3] | Via Babel (no type-checking while tests run) or ts-jest[7] |
| ES modules | Files go through Vite's plugin system[3] | "Experimental" support; needs --experimental-vm-modules and either transform: {} or an ESM-emitting transformer[8] |
Globals (describe, test, expect) | Off by default (globals: false)[5] | On by default[2] |
| Mock namespace | vi, imported from vitest[2] | jest; in ESM import it from @jest/globals[8] |
| Config file | vite.config.* or vitest.config.*[1] | jest.config.js, generated by npm init jest@latest[7] |
On speed, the Vitest docs say it uses worker threads to run as much as possible in parallel and that "some ports have seen test running an order of magnitude faster."[4] That is vendor-reported with no benchmark attached. Time your own suite before you sell the migration to your team.
The honest limit: both run in Node-based environments such as jsdom, which implements only part of the browser. The Vitest docs list window.navigation and layout properties like offsetTop as jsdom gaps, and suggest real-browser runners (Cypress, Playwright, WebdriverIO) alongside Vitest for browser-level checks.[3] Vitest also has its own browser mode, with documented limitations.[3]
Migrate from Jest to Vitest
The migration page opens by saying Vitest was designed with a Jest-compatible API, but you "may still run into" differences.[2] A workable order:
| Step | Action |
|---|---|
| 1 | Check Node.js is 22.12.0 or newer and Vite is 6.4.0 or newer[1] |
| 2 | Install Vitest with npm install -D vitest[1] |
| 3 | Either set globals: true or import describe, test, expect and vi from vitest[2] |
| 4 | Replace jest.* calls with vi.* equivalents (table below) |
| 5 | Replace jest.mock factories that return a bare value with an object that names each export |
| 6 | Change the test script to vitest (or vitest run in CI) and run the suite |
Step 5 is the one that trips most suites. In Jest, the factory's return value is the default export. In Vitest the factory must return an object with each export defined.[2]
// Jest
jest.mock('./some-path', () => 'hello')
// Vitest
vi.mock('./some-path', () => ({
default: 'hello',
}))
// Partial mocks: requireActual becomes importActual
const { cloneDeep } = await vi.importActual('lodash/cloneDeep')What breaks when you migrate
These come straight from the official Jest migration page.[2] Search your suite for each one before the first run.
| Jest habit | Vitest behavior | Fix |
|---|---|---|
| Globals available everywhere | Not provided by default. Libraries like testing-library will not run automatic DOM cleanup with globals off[2] | globals: true, or import from vitest |
mockReset gives an empty function returning undefined | Resets to the original implementation, so vi.fn(impl) goes back to impl[2] | Re-stub if you relied on the empty function |
| Factory return value is the default export | Factory must return an object with each export defined[2] | Wrap in { default: ... } |
<root>/__mocks__ loaded automatically | Not loaded unless vi.mock() is called[2] | Call vi.mock(), or mock inside setupFiles |
jest.requireActual | Use vi.importActual[2] | Rename and await it |
| Mocks reach external libraries that use the module | You must name the library in server.deps.inline[2] | server.deps.inline: ["lib-name"] |
done callback tests | Callback style unsupported[2] | Use async/await or return a Promise |
| Hook returns a value | A returned function is treated as a teardown. Hooks run in a stack, not one after another[2] | Use braces so the hook returns nothing; set sequence.hooks: 'list' for Jest order |
jest.Mock types | No jest namespace[2] | import type { Mock } from 'vitest' |
| Legacy fake timers | Not supported[2] | Use vi.useFakeTimers() |
jest.setTimeout(5_000) | Replace with vi.setConfig({ testTimeout: 5_000 })[2] | Rename |
-t 'math adds' | Names are joined with >, so use -t 'math > adds'[2] | Match one segment or use 'math.*adds' |
JEST_WORKER_ID | Counterpart is VITEST_POOL_ID; VITEST_WORKER_ID is the unique worker id[2] | Rename the variable |
Unchanged: like Jest, Vitest sets NODE_ENV to test if it was not already set.[2]
Vitest 5 changes that hit a fresh migration
The main migration page now covers upgrading to Vitest 5.0, and several of its changes bite someone arriving from Jest.[10]
| Change in 5.0 | What it does |
|---|---|
clearMocks defaults to true | Calls vi.clearAllMocks() before every test, clearing mock call history but keeping implementations. Calls recorded in beforeAll or a setup file are the most affected. Set clearMocks: false to keep the old behavior[10] |
vi.mock, vi.unmock, vi.hoisted inside a block | Now throws instead of warning, because the call is hoisted to the top of the file. Move it to the top level. vi.doMock and vi.doUnmock are not hoisted and may be called anywhere[10] |
Unawaited resolves / rejects | The test fails. Before 5.0 Vitest awaited them at the end and printed a warning[10] |
| Config lookup | Vitest no longer searches parent directories for config files. Pass --config ../vitest.config.ts from a subdirectory[10] |
| Worker ids | VITEST_POOL_ID and VITEST_WORKER_ID now start at 1, so per-worker database names or array indexes need an update[10] |
| JSON and JUnit reporters | Write to a file under .vitest/ by default instead of stdout, so vitest --reporter=json | jq stops working unless you set the reporter's stdout option[10] |
Common mistakes
Four mistakes cause most of the "Vitest is broken" reports, and each one traces to a documented default.
Turning on globals in config but not in TypeScript. globals: true makes the runtime work, yet the editor reports errors until vitest/globals is in types.[5] If you redefined typeRoots, add ./node_modules back so vitest/globals can be found.[5]
Keeping globals off and wondering why DOM tests leak. With globals disabled, testing-library skips its automatic cleanup.[2] Either turn globals on or call cleanup yourself.
Putting vi.mock inside describe. It never ran where it was written, and from 5.0 it throws.[10] Hoist it to the top of the file.
Running tests with the wrong command. Bun's bun test is not Vitest, and plain vitest starts watch mode by default, so use vitest run for a single pass.[1]
When to keep Jest
Vitest's pitch rests on sharing Vite's pipeline, so the case weakens when the project is not on Vite. The docs still call Vitest "a solid alternative even for projects not using Vite".[4] The comparison page names a library built with esbuild or Rollup as an example.[3] Reasons to wait are practical. A large suite leans on jest.mock factories that return default exports. It depends on automatic __mocks__ loading. It needs legacy timers, which Vitest does not support.[2] Each costs edits across many files, and the payoff is a faster feedback loop you have not yet measured on your code. Migrate one package or directory first, run both runners side by side, and compare the time and the failures before you move the rest.
Sources
- Getting Started, Vitest docs (accessed December 2, 2026)
- Migrating from Jest, Vitest docs (accessed December 2, 2026)
- Comparisons with Other Test Runners, Vitest docs (accessed December 2, 2026)
- Why Vitest, Vitest docs (accessed December 2, 2026)
- globals, Vitest config reference (accessed December 2, 2026)
- environment, Vitest config reference (accessed December 2, 2026)
- Getting Started, Jest docs, version 30.5 (accessed December 2, 2026)
- ECMAScript Modules, Jest docs, version 30.5 (accessed December 2, 2026)
- Releases, vitest-dev/vitest, GitHub (accessed December 2, 2026)
- Migrating to Vitest 5.0, Vitest docs (accessed December 2, 2026)
Written by
WOWHOW
The WOWHOW team brings 14+ years of production engineering experience. Every tool and product in the catalog is built, tested, and curated in-house.
Monday memo · free
One insight, every Monday. 7am IST.
1 field report, 3 links, 1 tool we actually use. No fluff, no spam.
Beyond the writing
Need production-ready templates?
Free browser tools with no signup, plus premium dev templates and starter kits.
Comments · 0
Beta: comments are stored locally on your device and not visible to other readers.
No comments yet. Be the first to share your thoughts.