Testing Hooks
Now our blog application makes full use of Hooks! We even defined custom Hooks for various functions to make our code more reusable, concise, and easy to read.
When defining custom Hooks, it makes sense to write tests for them to ensure they work properly, even when we change them later on or add more options.
To test our Hooks, we are going to use the Jest test runner, which is included in our create-react-app project. However, as a result of the rules of Hooks, we cannot call Hooks from the test functions because they can only be called inside the body of a function component.
Because we do not want to create a component specifically for each test, we are going to use the React Hooks Testing Library to test Hooks directly. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access