T
TanStack•3y ago
foreign-sapphire

React-Query v3 Can't get results to be returned when using Vitest with MSW

Hi everyone, So I'm in the process of upgrading my projects test suite to Vite and I've noticed that when trying to test the data fetching hooks that when I now return the data nothing is returned resulting in the tests failing (See attached image 1) When the hooks are used outside of the testing environment then the hooks work perfectly fine as far as I can see, so it's an issue in testing land. I've got to be missing some configuration or something as they were working fine when using jest with react-scripts but now I've introduced vitest and vite it's now misbehaving. Has anyone got testing working with reat-query and vite ? I would really appreciate any comments about my issue ? Technical details: Vite: v4.0.0 Vitest: v0.28.0 React-Query: v3.39.3 @testing-library/react: v13.4.0
No description
3 Replies
foreign-sapphire
foreign-sapphireOP•3y ago
Hmm weird it seems to be stuck in loading mode, almost like the promise isn't resolving.
foreign-sapphire
foreign-sapphireOP•3y ago
Hmm I'm more confused now. I've changed it to what Dominik has in his article and it works again https://tkdodo.eu/blog/testing-react-query
Testing React Query
Let's take a look at how to efficiently test custom useQuery hooks and components using them.
complex-teal
complex-teal•3y ago
Hi 👋 We can't reason about this without context. If you've got two examples (one that works and one that doesn't, which it sounds like you do) then please post sandboxes of those so we can have a look for you 🙂

Did you find this page helpful?