T
TanStack9mo ago
adverse-sapphire

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
adverse-sapphire
adverse-sapphireOP9mo ago
Specifically this means mocking isPending, not isFetching
other-emerald
other-emerald9mo 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
adverse-sapphire
adverse-sapphireOP9mo 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?