Skip to the page

Test runners, assertions and mocks · mid

Jest vs Vitest in 2026 (and Node's own test runner)

Jest 30 (June 2025) is still the default for React Native and many older web projects, Vitest (5.1 as of Nov 2026) is the common choice for Vite and modern ESM/TypeScript projects with a Jest-compatible API and a stable real-browser mode, and both are fine answers if you can explain the trade-offs.

The notes

What you must know

  • Jest 30: dropped old Node versions, jsdom 26, TypeScript config files, better ESM, big memory/speed gains in large repos, removed old expect aliases (toBeCalled etc.). Still the standard runner for React Native (@react-native/jest-preset since RN 0.85, or jest-expo).
  • Vitest: uses Vite's transform pipeline, so TS, JSX and ESM work without Babel config; watch mode is fast; API mirrors Jest (vi.fn, vi.mock, expect).
  • Vitest 4 (Oct 2025) made Browser Mode stable (tests run in real Chromium/Firefox/WebKit via Playwright) and added visual regression (toMatchScreenshot). Vitest 5 (Sep 2026) needs Node 22.12+ and Vite 6.4+, and turned on clearMocks by default.
  • DOM environments: jsdom (more complete) or happy-dom (faster) simulate the DOM in Node; Browser Mode runs the real thing (layout, CSS, focus).
  • Node has a built-in runner (node --test) with mocks and mock timers, good for libraries without a bundler.
  • Migrating Jest -> Vitest: mostly rename jest.* to vi.*, move config, check module mocking (vi.mock is hoisted too) and snapshot formats.

The red pen

Common traps: mistake → fix

  • Mistake: "Vitest only works with Vite apps"

    Fix: it runs any JS/TS project; Vite is just the transform engine.

  • Mistake: "jsdom tests prove the layout works"

    Fix: jsdom has no layout engine; sizes are 0; use Browser Mode or Playwright for layout.

  • Mistake: "Jest is dead"

    Fix: Jest 30 is maintained and remains the React Native default.

Easy to hard

Questions interviewers ask, easy to hard

  1. Jest or Vitest for a new React + Vite project? Why?
  2. What is jsdom and what can't it do?
  3. What does Vitest Browser Mode give you over jsdom?
  4. How would you migrate a 3,000-test Jest suite to Vitest safely?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview