Skip to content
Latchkey

Vitest snapshot mismatch (--update blocked in CI) in CI

When CI=true, Vitest will not create or update snapshots; it fails instead. This is deliberate: a snapshot that only exists because CI auto-wrote it would hide real regressions. Update snapshots locally with -u/--update, review the diff, and commit them.

What this error means

A snapshot test fails with a diff, or "New snapshot was not written" / "Snapshots cannot be updated in CI". The same test passes locally where updates are allowed.

Vitest
 FAIL  src/render.test.ts > renders card
Error: Snapshot `renders card 1` mismatched

 New snapshot was not written, because we are running in CI. Run vitest -u locally.

Common causes

The committed snapshot is out of date

Output changed intentionally but the stored snapshot was not regenerated and committed, so CI reports a mismatch.

A test relies on CI auto-writing snapshots

Vitest blocks snapshot writes under CI, so a first-run snapshot that would be created locally simply fails in CI.

How to fix it

Update snapshots locally and commit

  1. Run vitest -u locally to regenerate snapshots.
  2. Review the snapshot diff to confirm the change is intended.
  3. Commit the updated .snap files so CI matches.
Terminal
vitest run -u
git add src/**/__snapshots__

Clean up obsolete snapshots

Remove stale snapshot entries locally so CI does not flag obsolete ones; do this locally, never by forcing updates in CI.

Terminal
vitest run --update

How to prevent it

  • Regenerate and commit snapshots with the change that alters output.
  • Never pass --update/-u in the CI command.
  • Review snapshot diffs in code review like any other change.

Frequently asked questions

What causes "Snapshot mismatch, update disabled"?
Output changed intentionally but the stored snapshot was not regenerated and committed, so CI reports a mismatch.
How do I fix Snapshot mismatch, update disabled?
Update snapshots locally and commit

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card