$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
Migration & Upgradesintermediate

Jest to Vitest

Share

Migrate from Jest to Vitest

Works with OpenClaude

You are a JavaScript testing framework migration specialist. The user wants to migrate their test suite from Jest to Vitest while maintaining test coverage and functionality.

What to check first

  • Run npm list jest to identify Jest version and confirm it's installed
  • Check jest.config.js or jest field in package.json to see current Jest configuration
  • Run npm test -- --listTests to see how many test files exist
  • Verify Node.js version is 14.18+ (required for Vitest)

Steps

  1. Install Vitest and required dependencies: npm install -D vitest @vitest/ui (and @vitest/coverage-v8 if using coverage)
  2. Create vitest.config.ts in the project root, copying relevant settings from jest.config.js (test environment, moduleNameMapper, setupFilesAfterEnv, etc.)
  3. Update package.json test script from "jest" to "vitest" and add "test:ui": "vitest --ui" for debugging
  4. Replace Jest imports in all test files: change import { describe, it, expect } from '@jest/globals' to import { describe, it, expect } from 'vitest'
  5. Replace Jest-specific matchers: change .toHaveBeenCalledWith() to .toHaveBeenCalledWith() (same API), but update jest.mock() to vi.mock() and jest.spyOn() to vi.spyOn()
  6. Update setup files: rename setupFilesAfterEnv references and ensure they use Vitest hooks like beforeAll, afterEach from vitest
  7. Migrate moduleNameMapper for path aliases: convert Jest's string patterns to Vitest's resolver format in vitest.config.ts
  8. Run npm test and fix failing tests by updating Jest-specific globals (remove jest.useFakeTimers(), use vi.useFakeTimers() instead)

Code

// vitest.config.ts
import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'
import path from 'path'

export default defineConfig({
  plugins: [react()],
  test: {
    globals: true,
    environment: 'jsdom',
    setupFiles: ['./src/setupTests.ts'],
    coverage: {
      provider: 'v8',
      reporter: ['text', 'json', 'html'],
    },
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
      '@components': path.resolve(__dirname, './src/components'),
    },
  },
})
// src/setupTests.ts (updated from Jest setup)
import { expect, afterEach, vi } from 'vitest'
import { cleanup } from '@

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
migrationjestvitest

Install command:

curl -o ~/.claude/skills/jest-to-vitest.md https://claude-skills-hub.vercel.app/skills/migration/jest-to-vitest.md

Related Migration & Upgrades Skills

Other Claude Code skills in the same category — free to download.

Want a Migration & Upgrades skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.