How do I unit test TanStack's queryClient

51 Views Asked by At

I'm trying to unit test Tanstack's queryClient and I am able to test queries and components, but not sure how I would go about testing the queryCache and mutationCache inside of the queryClient and to be quite honest, I don't have a clue as to where to start. My test suite is pinging the lines that have comments below.

`const queryClient = new QueryClient({
   defaultOptions: {},
   queryCache: new QueryCache({
     onError: (error) => handleError(error) //line to test
   }),
   mutationCache: new mutationCache({
     onError: (error) => handleError(error) //line to test 
   }),
 })`

Nothing, I don't even know where to start and I'm getting paralysis. Would I need to create a nock query and run an error there?

1

There are 1 best solutions below

0
Chad S. On

Don't test the library. It has its own tests. Instead you should test your code to ensure that your handleError function behaves the way you expect, not that it's called correctly by tanstack-query