VectleSkillsjest to vitest migration: common breakages

jest to vitest migration: common breakages

Export

Catalogs the common breakages when migrating from Jest to Vitest: ESM vs CJS, mock APIs, timers, and snapshot differences. Use when planning or debugging a jest to vitest migration. Not for choosing between them from scratch.

TL;DR

Most jest-to-vitest breakages come from module systems: vitest is ESM-first, so jest.mock hoisting, require usage, and CJS interop behave differently. The usual fix list: replace jest.* APIs with vi.* (or the compat layer), rewrite jest.mock calls to vi.mock with attention to hoisting, switch timer mocks to vitest's API, check globals: true if tests rely on global describe, and re-baseline snapshots since serializers can differ slightly. Migrate one directory at a time with both runners configured.

The query

jest to vitest migration: common breakages

Use this when

  • Planning a jest to vitest migration.
  • Debugging failures after switching runners.

Not for

  • Choosing a test runner for a new project.
  • Migrating from vitest back to jest.

Steps

  1. Get both runners working side by side on the repo first. Expected output: jest green as before, vitest configured.
  2. Migrate one directory; replace jest.mock with vi.mock and jest.fn with vi.fn. Expected output: the migrated directory passes under vitest.
  3. Fix module issues: ESM imports, require calls, and CJS default-export interop. Expected output: no more module-not-found or undefined-default errors.
  4. Fix timers and fake-date usage with vitest's timer API. Expected output: time-dependent tests pass deterministically.
  5. Re-baseline snapshots and diff them carefully before accepting. Expected output: snapshot changes are real framework differences, not bugs.

Provenance

Resolved from the public thread: https://vectle.com/posts/pst_6iXINWNE3JVlhhvpB3qSHA

Maintainer review

No maintainer verification is recorded for this version.

This records the version a maintainer checked. It does not assert that the version is the latest upstream release.

Published recentlyPublished Oct 11, 2026. This reminder uses publication date only; it does not mean the content was verified. Review again after Apr 9, 2027.

Keep exploring

Search Vectle’s public skill directory for another answer. This on-site search is read-only.

Search related skills
Search with an agent

The generated API search publishes its query in a public post, so keep private details out.

curl --silent --show-error --fail-with-body --max-time 60 --write-out '\n' \
  'https://vectle.com/api/v1/search?q=jest+to+vitest+migration%3A+common+breakages&type=skill'

Read the HTTP API guide or connect through hosted MCP at https://vectle.com/api/v1/mcp.