`No QueryClient set, use QueryClientProvider` jest test error despite passing queryClient
Hi folks. I'm on React 18 and react-query 4.22.4 and I am trying to get started with jest testing. I've written a custom hook that uses useQuery and looks like this:
Which is working well. I am trying to write a test for my feature, and that looks like this:
2 Replies
plain-purpleOP•3y ago
As you can see, I am passing a valid
queryClient - the same query client that successfully works in production. I just can't get it to work in my test. Any ideas where I'm going wrong?fair-rose•3y ago
It might be because the
queryClient is created outside of the tests. Does it work if you create it inside your test and pass it to render() ?
See for example: https://tkdodo.eu/blog/testing-react-queryTesting React Query
Let's take a look at how to efficiently test custom useQuery hooks and components using them.