I find the Jest Snapshot Summary a bit confusing. After running tests in one of our repositories, I get the following Summary:
Snapshot Summary
› 2 snapshots written in 1 test suite.
› 50 obsolete snapshot files found, re-run with `-u` to remove them.
› 3 obsolete snapshots found, re-run with `-u` to remove them.
Snapshot testing means we compare the current tests' output against the output before our changes, to catch side effects.
Hence, if I get it right, the summary means
So running with -u
would
Is that understanding correct?
Snapshot tests are a very useful tool whenever you want to make sure your UI does not change unexpectedly. A typical snapshot test case renders a UI component, takes a snapshot, then compares it to a reference snapshot file stored alongside the test.
Snapshots have lots of benefits. They allow a quick roll-back to a previous point in time and allow for much more frequent protection than backups, without affecting production systems. Meanwhile, backups are likely to run once a day and outside main production hours because of their impact on resources.
- [Instructor] Snapshot tests are useful for making sure that the UI will not change unexpectedly. An additional Facebook package needs to be added to the project via npm to help us do that. It's called react-test-renderer, and it allows us to render React components as pure JavaScript objects.
So, snapshots make testing much easier. You can easily track code changes and fix errors. Also, it is easier to update the components when they change.
It's been a while I posted this question and by know I can answer it myself:
"Obsolete" refers to snapshots or snapshot files, for which no .toMatchSnapshot()
exists any more.
Snapshots are organised in one file per test suite. Single snapshots in those files are stored along with the name of their test, given in jest's it()
function. If you rename a test, the old snapshot is still in the snapshots file, but recognised as "obsolete".
› 2 snapshots written in 1 test suite.
⇒ 2 tests are new, no snapshots were available to compare against
This one holds true.
› 50 obsolete snapshot files found
50 tests still provide the same output as before
Is wrong, the 50 corresponding test suites have been renamed, moved or removed. Such a high number is unusual and you should probably find a way to re-map the snapshots to their tests, before updating them.
› 3 obsolete snapshots found
⇒ 3 tests have been removed, but the snapshots are still around
So this is only partly right, since the tests might have been renamed, not removed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With