DEV Community

Discussion on: Everything you need to know about React Hooks

Collapse
 
chasm profile image
Charles F. Munat

So would you disagree with this example:

medium.com/@MimiLiou77/testing-rea...

(Only one I've found.)

There is actually very little on best practices unless one goes off and takes something like the frontend masters courses. Personally, I think tests should always be discussed, even if to say what you've said above.

So you don't use mocks to mock out the implementation?

Thread Thread
 
vcarl profile image
Carl Vitullo

Mocking modules makes tests more fragile, I try to mock as little as is feasible when testing. Ideally I'd only use mocks for functions that I pass in, and I'd use those more as "spies" to make sure they're called correctly.

That seems like a solid testing example of a custom hook, as a unit test.

Thread Thread
 
chasm profile image
Charles F. Munat

I'm only mocking my own functions. I never mock libraries. I figure they should work fine.

I will give this some thought. Thanks for the responses.