T
TanStack3y ago
rival-black

How to mock refetch in jest with typescript

Hello! I have a custom hook that calls useQuery and exports its refetch property. How could I mock this in jest? its definition is <TPageData>(options?: RefetchOptions & RefetchQueryFilters<TPageData>) => Promise<QueryObserverResult<TData, TError>> , which means the return type itself has a refetch so not sure how to handle the recursion.
2 Replies
rival-black
rival-blackOP3y ago
for context, I am mocking the return values of this custom hook, and the only type i'm having issues with is this. I guess the alternative to this would be to mock useQuery itself and all the other hooks this hook makes use of.
foreign-sapphire
foreign-sapphire3y ago
I always recommended to only mock the network layer and nothing else

Did you find this page helpful?