Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I track 'snapshots' from JEST?

Or can I remove it from git? Beacuse it is annoying to add new commit just beacuse index.test.js.snap changed...

like image 598
John Taylor Avatar asked Mar 14 '18 06:03

John Taylor


People also ask

Should you use Jest snapshots?

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.

Where are Jest snapshots stored?

Jest has always been placing snapshots in the __snapshots__ folder right next to your tests.

How do I view Jest snapshots?

To review your snapshots, run npm run jest-html ( yarn run jest-html ). This launches your default browser and opens the jest-html application. By default, jest-html looks for snapshots under **/*. snap,!

Is a snapshot test a unit test?

The main difference between snapshot testing and functional/unit tests is, snapshot tests never assert the correct behavior of the application functionality but does an output comparison instead. There are two types of tools that support frontend snapshot testing.


1 Answers

The idea is that you put them into git, and next time the test is run it compares the result against the snapshot. If it gets the same result as the snapshot it will pass otherwise it fails. Without having the snapshots in git the whole concept would make no sense.

like image 52
Andreas Köberle Avatar answered Sep 21 '22 20:09

Andreas Köberle