DEV Community

Kristijan Pajtasev
Kristijan Pajtasev

Posted on

React snapshot tests - discussion

Recently i spent some time looking more into snapshot tests, and wondering on usefulness of full rendered ones.

If we use shallow renderer, subcomponents will stay as is and won't be replaced with their rendered version, in full renderer they will.

This means that any change in subcomponent will break parent component test and snapshot needs to be recreated. In system still in development, this can happen quite often. These snapshots are also much larger, therefore harder to review.

So I am interested to hear others opinion on them, how and how much are you using them and how useful do you find them?

Top comments (2)

Collapse
 
voluntadpear profile image
Guillermo Peralta Scura

Snapshot tests can be misused. You should check this article by Kent C. Dodds (the author of React Testing Library and the Testing JavaScript course) where he shares some recommendations on how to make them effective: kentcdodds.com/blog/effective-snap...

Collapse
 
hi_iam_chris profile image
Kristijan Pajtasev

Thank you Guillermo. I saw this post already, and it is a really good article. I really appreciate you posting it.