Migrate from Jest to Vitest.

Move a Jest suite to Vitest: globals, jest.fn, jest.mock factories, requireActual, timers, types, done callbacks and snapshots mapped to Vitest code, with a checklist, gotchas and live numbers for both tools.

Jest (live data): 45,486 GitHub stars. 63,211,142 weekly npm downloads (jest), +36% over 4 weeks. 0 GitHub releases in the last 60 days. last GitHub activity 2026-11-20

Vitest (live data): 17,430 GitHub stars. 193,983,069 weekly npm downloads (vitest), +49% over 4 weeks. 7 GitHub releases in the last 60 days, latest v5.1.1. last GitHub activity 2026-11-23

Globals: Jest: // describe, it, expect, jest are global test('adds', () => { /* ... */ }) → Vitest: import { describe, it, expect, vi } from 'vitest' // or: test: { globals: true } and "types": ["vitest/globals"] (Vitest globals are off by default.)

Mock function and spy: Jest: const fn = jest.fn() jest.spyOn(api, 'get') → Vitest: const fn = vi.fn() vi.spyOn(api, 'get')

Module mock with a factory: Jest: jest.mock('./some-path', () => 'hello') → Vitest: vi.mock('./some-path', () => ({ default: 'hello' })) (A Vitest factory returns the module's exports object, so a default export must be named.)

Real module inside a mock: Jest: const actual = jest.requireActual('./some-path') → Vitest: const actual = await vi.importActual('./some-path') (vi.importActual is async.)

__mocks__ folder: Jest: // <root>/__mocks__/axios.js is used automatically → Vitest: vi.mock('axios') // __mocks__ is only used after vi.mock()

Fake timers: Jest: jest.useFakeTimers() jest.advanceTimersByTime(1000) jest.useRealTimers() → Vitest: vi.useFakeTimers() vi.advanceTimersByTime(1000) vi.useRealTimers() (Vitest does not support Jest's legacy timers.)

Test timeout: Jest: jest.setTimeout(5_000) → Vitest: vi.setConfig({ testTimeout: 5_000 })

Mock types: Jest: const fn: jest.Mock<(name: string) => number> = jest.fn() → Vitest: import type { Mock } from 'vitest' const fn: Mock<(name: string) => number> = vi.fn() (There is no jest namespace in Vitest; import types from vitest.)

mockReset: Jest: fn.mockReset() // implementation becomes an empty function returning undefined → Vitest: fn.mockReset() // implementation goes back to the original (Same name, different result.)

Replace a property or env var: Jest: jest.replaceProperty(process.env, 'NODE_ENV', 'production') → Vitest: vi.stubEnv('NODE_ENV', 'production') // for other properties: vi.spyOn

done callback: Jest: test('loads', (done) => { load(() => { done() }) }) → Vitest: test('loads', async () => { await load() }) (Vitest does not support callback-style tests; return a promise or use async/await.)

Test environment: Jest: // jest.config.js testEnvironment: 'jsdom' /** @jest-environment jsdom */ → Vitest: // vitest.config.ts test: { environment: 'jsdom' } /** @vitest-environment jsdom */ (Both default to node. Vitest also reads the @jest-environment docblock.)

Hooks: Jest: beforeEach(() => setup()) // hooks run in the order they are declared → Vitest: beforeEach(() => { setup() }) // a returned function is treated as teardown // sequence: { hooks: 'list' } for Jest's order (Wrap one-line hooks in braces if they return something other than undefined.)

Worker id env var: Jest: process.env.JEST_WORKER_ID → Vitest: process.env.VITEST_POOL_ID

Coverage: Jest: jest --coverage → Vitest: npm i -D @vitest/coverage-v8 vitest run --coverage

Snapshots: Jest: // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing → Vitest: // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html (The header differs. Custom-hint snapshot keys use " > " instead of ":" (e.g. toThrowErrorMatchingSnapshot('hint')), and toThrowErrorMatchingInlineSnapshot stores [Error: msg] rather than just the message. Expect a diff on the first run.)

Checked against: jest 30.5.2, vitest 5.1.0 (npm registry, 2026-11-10)