Testing React Query Hooks and Components
You have almost mastered React Query! By now, you are well aware of how queries and mutations work and are ready to leverage React Query in a server-side, rendered project as well. Now, we’ll look at the last skill you need to be a full-on React Query hero – testing React Query using code.
This chapter will teach you how to test your useQuery
and useMutation
using components and hooks. But before that, you will get to know a super useful library to help you test your React Query code called Mock Service Worker.
You will then learn some restructuring tips and tricks you can leverage to make your React Query code more readable and reusable.
With this knowledge, you can start testing your code. You will start with testing your components that leverage React Query and see what testing from a user-centric approach looks like for queries and mutations.
Finally, we will dive into implementation details and see when and how...