Maintaining Snapshots

Learn the best practices for maintaining snapshot tests.

Intentional vs. unintentional changes

Like all tests, our snapshot tests are only as helpful as we design them to be. When designed and maintained properly, they can alert us to valuable insights regarding changes in our user interface. The tricky part about this is that obviously at times, we want our interfaces to change. We may have added a new feature or reworked the design of an existing one. Perhaps we were even fixing a recently uncovered bug in our user experience. These situations represent instances in which we are making intentional changes to our user interface, but Jest has no way of knowing this. It cannot differentiate on its own between intentional and unintentional changes within a new snapshot.

The fundamental idea behind tests is that they provide a level of confidence in knowing that our new code has not broken our old code. In an ideal world, especially when following practices like the open/closed principleThe open/closed principle states that code should be open for extension, but closed for modification., we add new tests to cover new code, and all of our existing ...