Skip to content
Home / Migrations / JestVitest

Jest Vitest

easy

Vitest is Jest-compatible but runs on Vite. Same expect/describe/it API, 10x faster with Vite's transform pipeline.

Estimated: 1-3h · 5 steps
Progress0%
Step 1: Install Vitest
npm install -D vitest && npm uninstall jest ts-jest @types/jest babel-jest
Step 2: Create vitest.config.ts

Minimal config — Vitest auto-detects test files.

import { defineConfig } from 'vitest/config'
export default defineConfig({ test: { globals: true, environment: 'jsdom' } })
Step 3: Update imports

If using globals: true, no imports needed. Otherwise: import { describe, it, expect } from 'vitest'.

Step 4: Replace jest.fn() with vi.fn()

Search and replace jest.fn/jest.mock/jest.spyOn with vi.fn/vi.mock/vi.spyOn.

find src -name '*.test.*' -exec sed -i 's/jest\./vi./g' {} +
Step 5: Update scripts

package.json: test → vitest, test:watch → vitest --watch.

All tests pass with vitest