DEV Community

Discussion on: Sanely Testing React Hooks

 
grug profile image
Dave Cooper

Thanks so much for the in-depth response. It's very cool getting to discuss this stuff with you.

(I bet there are lots of people that aren't unmounting their components to test that their effects get cleaned up correctly).

One of the great features of custom hooks is that they can hide away a tonne of complexity behind a simple API for the component to consume. When you test through the component, it's easy to miss those edge cases, especially when the component is consuming multiple complex custom hooks and passing values between them.

Couldn't agree more about this!

Personally, I find mocking out things like a Redux store to be a bit futile sometimes.

Me too - I'm trying to find something that exists to make life a bit easier when it comes to either mocking the Redux store for tests or just a nice pattern that allows people to use a provider in their tests (not just when it comes to testing hooks)