beeboop
beeboop

Reputation: 41

How do I unit test TanStack's queryClient

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?

Upvotes: 2

Views: 608

Answers (1)

Chad S.
Chad S.

Reputation: 6633

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

Upvotes: 0

Related Questions