Jest Snapshot testing vs unit testing?

General Tech QA/Testing 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on QA/Testing related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

It's fairly easy to implement snapshot testing in jest but it's something I am not really comfortable with because it feels like I am not actually testing anything. In unit testing I can easily take my components under test and put expectations on the their actual behavior and also test what they should be rendering. But all I can see about snapshot testing is that it yields when you change something and shows you the difference! I can do that using git diff app.js!

profilepic.png
manpreet 2 years ago

You can think about a snapshot test as a unit test with an auto generated assumption about your component.

The advantages are that you can easily test complex structures without writing much code, that you get good warnings when something changed and that you can easily update this test.

The disadvantages are that from just reading the test it is not always clear what is tested and what the expected behaviour is, that it could happen that the created snapshot is so complex that you overlook wrong assumptions that then end up as expected result and that it is so easy to update snapshots that wrong stuff can sneak in.

So when using snapshot test its really important to make them more granular, so not always testing the whole component, but have some smaller test that test parts of it and to have good code review culture, to spot bugs in the snapshot.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community