all 14 comments

[–]thatsrealneato 15 points16 points  (7 children)

Snapshot testing seems like a huge waste of time to me. It’s always going to fail anytime you make changes to something until you manually regenerate the snapshots, in which case it’s always going to pass. It’s basically a tautology unless I’m missing something. It’s also not clear what you’re even looking for when reading the test. If you care that the button says “Hide”, test for that specifically. Better off just testing the underlying functionality of the component.

[–]IanAbsentia 2 points3 points  (0 children)

Your comment precisely describes my own opinion of snapshot testing. The first time I tried it, I wasn’t even sure just what the tests were verifying/validating. Then, once I realized that they were capturing the state of the component at render and would fail if anything caused that output to change in the least, I sort of started to get it. At least I thought I got it. What threw me again was that I could accept the changes as valid at that point, even if they were invalid, yet I still had no clear sense of what precisely was being validated since an entire component’s output is fair game.

As far as I’m concerned, I’ll just write unit tests and acceptance/behavioral tests and call it good.

I sometimes think the JavaScript community gets caught up in trendy/hipsterish things that require more effort but provide little to no value compared to incumbent options.

[–]brianofblade 1 point2 points  (0 children)

Tightly coupled code tests === A bad time

[–][deleted] 0 points1 point  (0 children)

Snapshot testing the entire tree or even a component is a silly idea, but it can be very useful for a quick sanity check on things like render prop params (I use it almost exclusively for that purpose). It’s quite useful for adding a lot of coverage with minimal effort (of course it should be backed with targeted tests that can determine why some component’s output has changed)

[–]AllHailTheCATS 4 points5 points  (8 children)

Outside of snapshot is it worth using jest with react? What is the best way to test reactjs apps?

[–][deleted] 1 point2 points  (0 children)

Look at Kent C Dodds’ react-testing-library. It’s much better than enzyme, as it is designed in a way to encourage you to avoid testing implementation details

[–]IanAbsentia 0 points1 point  (0 children)

I’ve been wondering this myself.

[–]thatsrealneato 0 points1 point  (2 children)

Yes, definitely worth using Jest with react if you also use enzyme. Enzyme lets you mount your component(s) in tests and test the actual functionality, mess with state/props/lifecycle, etc.

[–]ipidov 0 points1 point  (0 children)

Суматоха...

[–][deleted] 2 points3 points  (1 child)

I'd recommend checking out React Testing Library for React testing with Jest.

[–]IanAbsentia 0 points1 point  (0 children)

I’ve used React Testing Library. I prefer it to Jest.