New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ls-guillaume-lambert opened this Issue May 11, 2017 · 5 comments

Comments

Projects
None yet
5 participants
@ls-guillaume-lambert

ls-guillaume-lambert commented May 11, 2017

@mcMickJuice

This comment has been minimized.

mcMickJuice commented May 11, 2017

Had the same thought after watching this presentation:

https://youtu.be/HAuXJVI_bUs

@kentcdodds

This comment has been minimized.

Owner

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.

@marcusnielsen

This comment has been minimized.

marcusnielsen 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

This comment has been minimized.

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

This comment has been minimized.

Owner

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 join this conversation on GitHub. Already have an account? Sign in to comment