Skip to content
Latchkey

Vitest snapshot mismatch with updates disabled in CI

When Vitest detects CI, it disables snapshot writing. A new snapshot is not created and an outdated one is not updated, so toMatchSnapshot fails rather than silently passing by rewriting the file.

What this error means

A snapshot assertion fails in CI with a diff, or with a note that new snapshots are not written in CI. The same test passes locally because local runs create or update snapshots automatically.

Vitest output
❯ src/Card.test.tsx > renders
   Error: Snapshot `renders 1` mismatched

   - Expected
   + Received

   (new snapshots are not written automatically in CI)

Common causes

A snapshot was never committed

The test produces a snapshot that exists locally but was not committed, so CI has no baseline and refuses to write one.

Output drifted from the committed snapshot

Rendered output changed but the snapshot was not updated, and CI mode will not rewrite it, so the diff fails the test.

How to fix it

Update and commit snapshots locally

  1. Run Vitest with -u to refresh snapshots.
  2. Review the diff to confirm the change is intended.
  3. Commit the updated snapshot files.
Terminal
npx vitest run -u
git add **/__snapshots__/*.snap

Keep snapshot files tracked

Make sure snapshot directories are not gitignored so CI sees the committed baseline.

.gitignore
# .gitignore should NOT contain:
# __snapshots__/

How to prevent it

  • Commit snapshots together with the code that produces them.
  • Review snapshot diffs before pushing.
  • Do not gitignore __snapshots__.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →