Skip to content
This repository has been archived by the owner. It is now read-only.

Would you recommend using Jest snapshots for *almost* everything? #275

Closed
glambert opened this issue May 11, 2017 · 5 comments
Closed

Would you recommend using Jest snapshots for *almost* everything? #275

glambert opened this issue May 11, 2017 · 5 comments

Comments

@glambert
Copy link

@glambert glambert commented May 11, 2017

This is regarding the tweet you've made here: https://twitter.com/kentcdodds/status/862343047258009604?refsrc=email&s=11

Questioning myself after reading this article: https://hackernoon.com/how-to-snapshot-test-everything-in-your-redux-app-with-jest-fde305ebedea

Thanks!

@mcMickJuice
Copy link

@mcMickJuice mcMickJuice commented May 11, 2017

Had the same thought after watching this presentation:

https://youtu.be/HAuXJVI_bUs

@kentcdodds
Copy link
Owner

@kentcdodds kentcdodds commented May 11, 2017

Hi friends! So this is a pretty common question and I decided to give it justice by recording a short 3 minute podcast about it. You can listen to that here (subscribe: itunes rss)

I hope that helps! Feel free to ask follow-up questions.

@marcusradell
Copy link

@marcusradell marcusradell commented May 21, 2017

I use snapshots for testing state reducers/updaters. The benefit is that I can treat the entire state of a component as a unit. If someone changes the state-shape, all updater functions are affected. It might seems like overkill, but we added an errors prop to the state, which should be reset if we successfully load data. The snapshot asks the question: "are you sure that the entire state shape should look like [xyz] in this test?", which I think is a pretty good checklist to go through.

Edit: I'm wondering how easy it is to onboard people on snapshot testing compared to equality checks. I find that snapshotting is a simpler concept to grasp for junior people.

@blocka
Copy link

@blocka blocka commented May 21, 2017

That would require you and everyone on your team to have in their head the knowledge of how the state is supposed to look, and rely on having all your developers being awake (this is the major problem with snapshots, actually).

I think it's much better to be able to have a computer verify this.

@kentcdodds
Copy link
Owner

@kentcdodds kentcdodds commented May 21, 2017

I agree with @blocka. The bigger the snapshot, the less carefully it's reviewed. It's a trade-off. But if you can use another assertion to be more specific, or if you can snapshot a smaller portion then that's better IMO

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants