Advertisement
Advanced JavaScript, Debugging, Testing & Tooling

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

Short 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.

Save JavaScript mock interview
Advertisement
AModel 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.
Likely follow-ups
  • How do you review a snapshot diff meaningfully instead of just accepting it?
Related topics