TanStackT
TanStack3y ago
3 replies
then-purple

Testing Component that uses UseQuery hook

Hello !
I don't know if I'm following the right logic on this, do not hesitate to tell me i'm wrong.

I have a component that uses the data from a custom useQuery to conditionally render the content of my page.
I want to test the different outputs of my component which depends on the result of my useQuery.

Right now, I have my QueryProvider setup, my axios call is mocked, but when I try to assert on what my component render, I get an error as data is considered undefined.
I'm considering mocking the useQuery as I can already verify the hook itself in another test. Would that be correct, and if so, how can I do that in Typescript ?

The error:
Error: Uncaught [TypeError: Cannot destructure property 'data' of '(0 , _profile.useGetUserPermissions)(...)' as it is undefined.]


I'll put the code samples in the thread. (i'll check if I can quickly reproduce a codesandbox)
Thanks
Was this page helpful?