If you’re doing React, then this includes shallow rendering
Write tests. Not too many. Mostly integration.
Kent C. Dodds
6.8K22

Thanks for posting your opinion. Interesting read.

Nonetheless I disagree with you about shallow rendering is bad practice. When you do unit test you want to test in isolation because you want to know exactly what point of you application is failing. This info is crucial for fixing bugs quickly.

When you have an integration test that fails, you don’t know what and where it failed.

Let’s take your human example. Humans only feel pain. So know you feel pain at your stomach. But what does that mean? What exactly is causing the pain? You just don’t know. You have to go to the doctor and check every thing that could cause this type pain. That is very time consuming.

To your react example. Your friend is just testing the wrong things. That has nothing to do with using shallow or mount. The state of a component is something internal. He should treat a component like a function. To test a function you give it specific params and test that the result matches your expectations.

The same is true for a component. You pass it specific props (function params) and check if it returns the expected result (return from render function).

Nevertheless I think integration test are also important. But I just want to clarify that unit tests and shallow rendering are also good things.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.