DEV Community

Discussion on: Jest Snapshot Testing for React Components is useless? Is it slowly dying? 🧐🤔😐

revskill10 profile image
Truong Hoang Dung

They're just tools, they solved specific problems (in this case, snapshot testing, not unit test, not integration test).

It's not the tools false, it's the human using it the wrong way.

destro_mas profile image
Shahjada Talukdar Author

Thanks for your opinion!

But what do you think about the example I gave in this Article?
Do you think snapshot testing is good for this kind of case?

barakplasma profile image
Michael Salaverry

I think snapshot testing is good for testing single components like your example anchor component.

Especially when the typical alternative is writing many selectors and expectations by hand.

Using snapshots to test the root element of an entire SPA is a mistake since snapshot update fatigue is real, but that doesn't make snapshots useless.

That being said, there are visual regression testing tools worth looking into as a replacement for jest snapshots.

Thread Thread
destro_mas profile image
Shahjada Talukdar Author

The example is actually just a placeholder. But let's assume it as a bigger component and then the snapshot will be very big and if we change the component and generate snapshot again, the diff will be very big too.

Also, Doing visual snapshot testing can be a good thing and can also get potential UI bugs. And tools like Percy can be a good replacement.