cliff-effects icon indicating copy to clipboard operation
cliff-effects copied to clipboard

Replace _all_ `shallow()` test renderings with `mount()`

Open knod opened this issue 7 years ago • 3 comments

Other than the shallow tests not catching bunches of stuff, I think we may find some things not right with our components.

knod avatar Nov 04 '18 02:11 knod

Or do .not.Throw() instead. One or the other.

knod avatar Nov 04 '18 11:11 knod

I've read the opposite advice; use shallow() unless you need something that shallow() can't do. One reason for this is that it can help you avoid needing to set up context/etc. for nested components--for example, React Router's <Link> component requires a router in its ancestry, and will throw an error if it doesn't find it. But if you're testing a component that contains a <Link> but the bit you're testing doesn't need to render the link, you can avoid that. In general, I think the idea is to only test the specific case you're testing.

turnerhayes avatar Nov 06 '18 23:11 turnerhayes

I hear some of that. Can't we add context and routers to our test, though? Here's an article about shallow rendering that seemed to resonate: https://blog.kentcdodds.com/why-i-never-use-shallow-rendering-c08851a68bb7

knod avatar Nov 07 '18 12:11 knod