Skip to main content

Jest to Vitest Migrator

Paste your jest.config.js or test file — get the Vitest equivalent instantly. Converts config structure, jest.fn() → vi.fn(), moduleNameMapper → resolve.alias, and more.

✓ jest.config.js → vitest.config.ts ✓ jest.fn / jest.mock / jest.spyOn → vi.* ✓ moduleNameMapper → resolve.alias ✓ Transform config cleanup

Quick Reference: Common Replacements

jest.fn()→vi.fn()
jest.mock()→vi.mock()
jest.spyOn()→vi.spyOn()
jest.useFakeTimers()→vi.useFakeTimers()
jest.clearAllMocks()→vi.clearAllMocks()
jest.resetAllMocks()→vi.resetAllMocks()
jest.restoreAllMocks()→vi.restoreAllMocks()
jest.setTimeout()→vi.setConfig({ testTimeout })

Frequently Asked Questions

What is the main difference between Jest and Vitest configuration?▼

Jest uses jest.config.js/ts with a top-level object, while Vitest uses vitest.config.ts wrapping settings inside a test: {} block via defineConfig(). Vitest also reuses your existing vite.config.ts, so many settings like path aliases transfer automatically. The biggest change is swapping preset/transform settings for Vitest's native ESM and TypeScript support.

Do I need to change my test files when migrating from Jest to Vitest?▼

For most projects, minimal changes are needed. Vitest is Jest-compatible — describe, it, test, expect, beforeEach, afterAll all work identically. The main differences are: (1) import { vi } from 'vitest' instead of using jest global, (2) vi.fn() instead of jest.fn(), (3) vi.mock() instead of jest.mock(). If you enable globals: true in vitest.config.ts, you don't even need to import these.

How do I migrate jest.mock() to vi.mock()?▼

Replace jest.mock('module') with vi.mock('module'). The factory function syntax is identical. For manual mocks in __mocks__/ directory, Vitest supports the same pattern. For module-specific mocks, use vi.mock('module', () => ({ default: vi.fn() })). The key difference: use vi.spyOn() instead of jest.spyOn(), and vi.resetAllMocks() instead of jest.resetAllMocks().

What happens to my Jest transform/preset configuration?▼

Vitest handles TypeScript and JSX natively via Vite — no need for ts-jest, babel-jest, or @babel/preset-env. Remove these from your config entirely. If you used @swc/jest for speed, Vitest already uses esbuild by default (even faster). The only transform you might need is for CSS or static assets (handled the same way as in vite.config.ts).

How do I handle moduleNameMapper when migrating to Vitest?▼

Jest's moduleNameMapper becomes resolve.alias in vitest.config.ts (or vite.config.ts). Convert { '^@/(.*)$': '<rootDir>/src/$1' } to { '@': path.resolve(__dirname, './src') } in the resolve.alias block. This is identical to Vite path aliases — if you already have vite.config.ts with aliases, Vitest inherits them automatically.

Should I use globals: true or explicit imports in Vitest?▼

Explicit imports (import { describe, expect, vi } from 'vitest') are the recommended approach for new projects — they're more explicit and TypeScript-friendly without extra tsconfig setup. However, if you're migrating a large codebase from Jest, enable globals: true temporarily to avoid touching every test file, then gradually migrate to explicit imports as you update each file.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →