DEV Community

Discussion on: Why I've Stopped Writing Snapshots Tests in Jest

Collapse
 
avidanfeldman profile image
Avidan Feldman • Edited

i must say that you brought up some good points in your post however i think that this is kinda looking at snapshots testing without any context. i'll try to explain what i mean regarding the 3 claims you mentioned:

  1. "It's really hard to be specific as to what your test is actually testing"
    i think this is relevant to any test methods/tools that you choose to work with - when you write a test one of your major issues is to make sure that someone else who reads your test will understand exactly what you are testing (giving a good "describe" and "it" titles helps, but there are other ways too). if you do not do that then with no doubt the test is bad.
    writing good tests takes time... there are no shortcuts.

  2. "Constant updating of snapshots can create an "if-it-doesn't-pass-just-update-it" attitude"
    oh wow, this statement is bad. like really really really bad.
    this is pretty much saying that when you write a code you have no responsibility what so ever to what you write and that you don't try to understand the implications of changes you made in the code. maybe i'm a bit harsh but if i find someone in my organisation who behaves like that then either he does not understand what snapshots are made for or he should be fired...

  3. "They provide no helpful information as to how the code is used"
    now THAT is something i can def relate to. indeed snapshots have little information regarding the code. this is why snapshots are very bad when it comes to test the functionality behaviour of the components (as apposed to just rendering) - that should be done using specific tests and not snapshots.
    the big strength of snapshot comes in testing render result of the component with different props. when it comes to rendering they give you a 'good enough' direction as to what changed and from there it's usually pretty easy to find the prob in the code.

to sum things up, i think that jest snapshot is a powerfull tool, and with great power comes great responsibility. use it wisely and it will serve you well. abuse it and it will come back at ya...