Open knod opened 6 years ago
Or do .not.Throw()
instead. One or the other.
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.
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
Other than the shallow tests not catching bunches of stuff, I think we may find some things not right with our components.