TkDodo / testing-react-query

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vitest Integration

dmoxyeze opened this issue · comments

Can you please do an example with the vitest library?

I am using vitest for testing. However, my tests do not return any outputs.

I've not yet had the opportunity to use vitest. Would you like to contribute an example?

Sure! But I am yet to get it to work properly. Right now, with what I have, the tests do not return any results and they do not fail.

I don't mind sharing code samples.

yes please do share, preferably in codesandbox, if you have something that fails.

Okay, I will.

Hi! Just managed to get a testing setup working with React Testing Library, MSW, Vitest and React Query, so I thought I'd share some resources in case anyone else is looking for this.

Luckily, the Vitest docs has many great examples, including one called react-testing-lib-msw which will take you 90% of the way there. Here's the GitHub repo and an online playground.

Just note that this example is using MSW > 2.x, so there are breaking changes in comparison to the setup used in this repo, but they are not too complicated and there's an official upgrade guide. Also, I'd be glad to contribute with an MSW v2 example for this repo, if needed.

Once that's done, the logic for testing React Query is the same as what's explained in this repo.