The snapshot testing tool

1 min read

Kent C Dodds mentions in his article about snapshot testing when referring to a particular snapshot.

"What makes this snapshot good is it can communicate the intent by the title of the snapshot"

I think this is the most important guideline for good snapshot testing. Your test should assert very few things in its title and when the tests fail it's because the codes no longer is doing what is asserted the test's title, not because of something unrelated.

If that's hard to do it is likely that the snapshot is too large which is another indicator itself that snapshots might not be the right tool for the job.

I also found Chris Girards guidelines around "When to write a snapshot test" helpful and similar:

  • If a component is not updated often
  • If a component is not too complex
  • If it is easy to see what you are actually testing

Snapshot testing can easily fall to the "Golden hammer" fallacy. If all you have is a hammer, then everything looks like a nail.

Was this article helpful?