Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Jest Snapshot testing vs unit testing?

General Tech QA/Testing
Max. 2000 characters
Replies

usr_profile.png
Deepak Parmar

User

( 6 months 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!

usr_profile.png
Charles Kyobe

User

( 6 months 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.

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif