Hooks are an implementation detail, if used within a component. I specifically try to write UI tests that manipulate the DOM and verify that callbacks were called correctly (what I view as the inputs and outputs of a UI--react-testing-library is excellent for this), so whether I use hooks or something else the tests would be the same. Indeed, I'd consider it a faulty test if I had to dramatically change my strategy by adding hooks.
As for writing tests for custom hooks, that is definitely new and valuable, but seems beyond the scope of an API overview. If you'd like to try it out and write up your experience with it, I'm sure it would be valuable.
I work with pedagogies, teach, write curricula, coach, manage, mentor, consult, speak publicly, polemicize, and sometimes work as a full-stack web developer, architect, ontologist, and more.
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?
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.
I work with pedagogies, teach, write curricula, coach, manage, mentor, consult, speak publicly, polemicize, and sometimes work as a full-stack web developer, architect, ontologist, and more.
Hooks are an implementation detail, if used within a component. I specifically try to write UI tests that manipulate the DOM and verify that callbacks were called correctly (what I view as the inputs and outputs of a UI--
react-testing-library
is excellent for this), so whether I use hooks or something else the tests would be the same. Indeed, I'd consider it a faulty test if I had to dramatically change my strategy by adding hooks.As for writing tests for custom hooks, that is definitely new and valuable, but seems beyond the scope of an API overview. If you'd like to try it out and write up your experience with it, I'm sure it would be valuable.
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?
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.
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.