Community JavaScript Snippet

How I Stopped My Jest Snapshots From Churning

A serializer that strips dates, ids, and request hashes out of snapshot JSON so a fresh git clone does not nuke the snapshot diff. Drop into `snapshotSerializers` and forget.

How I Stopped My Jest Snapshots From Churning

A serializer that strips dates, ids, and request hashes out of snapshot JSON so a fresh git clone does not nuke the snapshot diff. Drop into `snapshotSerializers` and forget.

JavaScript
Frontend
3 snippets
testing
unit-testing
utility
code-template
marcusreddy

By @marcusreddy

December 14, 2025

·

Updated May 20, 2026

368 views

12

4.2 (11)

The win is in two layers: a key-name denylist for fields you know are volatile (createdAt, requestId, traceId) and a value-shape sweep for things that look like dates, uuids, or hashes regardless of where they appear. I have learned to keep them separate because the shape sweep catches surprises: an upstream API adds a metadata.runId: '7c1ad9...' and your snapshot does not break. The output uses angle-bracket tokens (<ISO_DATE>) rather than dropping the field, so a missing field still fails the snapshot but a churning timestamp does not.