Back to results for “Debugging”
JavaScript › Debugging, Testing & Tooling

What is snapshot testing and what's a common pitfall with it?

Advanced

Answer

Snapshot testing saves a serialized representation of a component/output and fails future test runs if the output changes unexpectedly. The pitfall is developers blindly running 'update snapshots' without reviewing the diff, which silently approves real regressions.
expect(renderComponent(<Button label='Save' />)).toMatchSnapshot();
Real-world example Catching accidental UI markup changes in a design-system component library.

Common follow-ups: How do you review a snapshot diff meaningfully instead of just accepting it?