DevFlow logoDevFlow
JestVitestAutomated Breaking Change Check

Migrate Jest Unit Tests to Vitest

Convert Jest test suites, configs, and mocks to Vitest. Share identical Vite configurations and execute tests 4x faster with ESM native workers.

From: Jest
To: Vitest
Source (Jest)
495 chars
Migrated Target (Vitest)
1ms540 chars
import { describe, it, expect, vi } from 'vitest';
import { UserService } from './user-service';

describe('UserService', () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  it('fetches user details and formats response', async () => {
    const mockFetch = vi.fn().mockResolvedValue({ id: '1', name: 'DevFlow' });
    vi.spyOn(global, 'fetch').mockImplementation(mockFetch as any);

    const user = await UserService.getUser('1');
    expect(user.name).toBe('DevFlow');
    expect(mockFetch).toHaveBeenCalledTimes(1);
  });
});

Detected Breaking Changes & Semantic Shifts (1)

Mock Replacement: jest.fn() -> vi.fn()
info

Vitest replaces the global `jest` namespace with `vi` (`vi.fn()`, `vi.spyOn()`, `vi.mock()`).

Resolution: Import `vi` from "vitest": `import { vi } from "vitest";`.

How to Migrate from Jest to Vitest

  1. 1

    Paste your Jest unit test file or jest.config.js.

  2. 2

    The migrator swaps `jest.fn()` and `jest.spyOn()` for Vitest `vi` equivalents.

  3. 3

    Global test assertions are converted to explicit ESM imports for TypeScript safety.

  4. 4

    Run `bun test` or `vitest run` to execute test suites instantly.

Run Vitest in CI Pipeline

.github/workflows/test.yml
name: Tests
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: bun install
      - run: bun run test:run

Run Migration via Terminal CLI

Perform identical migration routines across entire directories or repositories in your local terminal:

devflow migrate jest-to-vitest -i tests/

Frequently Asked Questions

Can Vitest run Jest test files without modifying code?
Yes! By adding `test: { globals: true }` in `vitest.config.ts`, global `describe`, `it`, and `expect` remain globally available.
Was this guide / tool helpful to you?