Using the React Hooks Testing Library, we can also test more complex Hooks, such as Hooks making use of React context. Most of the custom Hooks we created for our blog app make use of contexts, so we are now going to test those. To test Hooks that use context, we first have to create a context wrapper, and then we can test the Hook.
In this section, we are going to perform the following:
- Create a ThemeContextWrapper component
- Test the useTheme Hook
- Create a StateContextWrapper component
- Test the useDispatch Hook
- Test the useUserState Hook
- Test the usePostsState Hook
Let's get started.