Snapshot testing
Use snapshot tests for serialized output only, with disciplined review of every diff and hard limits on snapshot size. Use when pinning stable rendered output like markup or an API response shape.From its SKILL.md
npx -y skills add Amey-Thakur/AI-SKILLS --skill snapshot-testingAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- 23 days oldThe repository was created 23 days ago. New is not bad, but a brand new repository carrying a familiar-sounding name is the shape a typosquat arrives in, and there has been no time for anyone else to find a problem with it.
- 4 stars4 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
2.7 KB, 553 tokens by cl100k_base, as published. Nobody here has run it
Snapshot testing
A snapshot test records a serialized output once and fails when it changes.
Used well, it pins a component's rendered markup or a response's shape
cheaply. Used badly, it becomes the worst kind of test: a giant blob nobody
reads, a diff approved with --update on reflex, a green check that asserts
only that today equals yesterday. The discipline is limiting what you
snapshot and treating every diff as a claim to verify.
Method
- Snapshot serialized output, not behavior. Snapshots fit stable serializable artifacts: rendered HTML, a JSON response, a formatter's output. For logic with a known expected value, write an explicit assertion, since a snapshot there only hides the intent.
- Keep each snapshot small enough to read. Cap it at what a reviewer will actually scan, roughly a screen. Snapshot one component, not a whole page tree. A thousand-line snapshot gets rubber-stamped, which defeats the test.
- Review every diff as a real change. A snapshot diff is the test asking whether you meant to change this. Read it, confirm the change is intended, and only then update. Update-all in a hook or CI turns the test into a rubber stamp.
- Strip nondeterminism before serializing. Replace timestamps, UUIDs,
and random ids with property matchers like
expect.any(String)or stable fixtures. A snapshot that changes every run trains people to ignore its diffs. - Store snapshots as reviewed source. Commit them, read them in the pull request like code, and never let a snapshot land unseen. A snapshot nobody looked at is a recorded output, not an assertion.
- Prefer inline snapshots for small values. Keep short snapshots inline
with the test using
toMatchInlineSnapshotso the expected output sits next to the code, not in a distant.snapfile the reader never opens.
Litmus tests
- Could a reviewer read this snapshot's diff and judge whether the change was intended?
- Does the snapshot exclude every value that varies between runs?
- Is anything asserted here by snapshot that a three-line explicit assertion would state more clearly?
Boundaries
Snapshots pin serialized output, they do not verify logic or catch behavior a human never reviews: for value assertions use unit-test-design, and for large legacy outputs use golden-master with its own diff workflow. Follow the framework's snapshot format, Jest, Vitest, or insta, over the specifics here.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.