T
TanStack12mo ago
national-gold

How to mock loading/error states.

In storybook I'm using setQueryData to set mock data. How can I manually set loading/error states?
3 Replies
national-gold
national-goldOP12mo ago
Specifically this means mocking isPending, not isFetching
genetic-orange
genetic-orange12mo ago
I'd go with mocking the queryFn and not using setQueryData Because I think once you setQueryData, sucess will always be true so for isPending have a queryFn that never resolves, for isError, have a promise that immedially rejects
national-gold
national-goldOP12mo ago
Yeah, maybe setQueryDefaults([..keys], {}), instead? I kind of want to avoid passing in mock params, so I can work with integration tests too.

Did you find this page helpful?