JavaScript & TypeScript / Quiz

Snapshots: Rubber Stamp or Regression Net

toMatchSnapshot, the -u reflex, dates that break every run, and the CI flag that stops snapshots from lying by omission.

Difficulty
Easy
Format
Quiz
Points
100
Estimate
8 min

// MISSION BRIEF

Your Mission

Snapshot testing is the easiest assertion to write and the easiest to stop reading. A snapshot suite is either a regression net or a pile of rubber stamps, and the difference is workflow, not tooling.

This quiz covers how snapshots are written, updated, and reviewed, plus the determinism traps (dates, ids) that make them flake.

Speed bonus active.

// FIRST CONTACT

Battle teaser

The very first run of expect(render(<Badge/>)).toMatchSnapshot() on a machine with no snapshot file:

  1. AFails, because there is nothing to compare against
  2. BWrites the snapshot to __snapshots__/... and passes, snapshots assert against their own recorded past, so run one records
  3. CCompares against an empty string and fails
  4. DPrompts interactively for approval before writing
Answers, scoring, hints, and the full battle stay sealed.

// SKILL TAGS

javascriptjestsnapshot-testingunit-testing