-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: make sure paused queries resolve #909
feat: make sure paused queries resolve #909
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/tannerlinsley/react-query/2fzpd8qp7 |
6c0f210
to
b7b472e
Compare
b7b472e
to
49560ac
Compare
49560ac
to
673b8eb
Compare
673b8eb
to
ff5b5ed
Compare
ff5b5ed
to
867d8f9
Compare
867d8f9
to
d489494
Compare
d489494
to
bbc8b8e
Compare
bbc8b8e
to
48cf3ef
Compare
48cf3ef
to
3cb8713
Compare
3cb8713
to
7ab470b
Compare
7ab470b
to
1fb66e9
Compare
1fb66e9
to
88d94a5
Compare
🎉 This PR is included in version 2.11.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
FYI, with this release, I started seeing new |
Oh, and also, with this change coming to React Testing Library it's even worse. I'm not sure why yet, but yeah, there's an issue with this change for sure. |
Hi @kentcdodds! I'm not familiar with the exact details of Based on the number of renders: await waitFor(() => expect(states.length).toBe(4)) Based on some time: export function waitForMs(ms: number) {
const end = Date.now() + ms
return waitFor(() => {
if (Date.now() < end) {
throw new Error('Time not elapsed yet')
}
})
} |
Ok, here's an update. This appears to only be a problem when using fake timers (this test is the culprit). If I add a I think what would help more is to make sure that when I call |
Ok, I'm pretty sure I know what's going on. It looks like what happens is:
I can get rid of the act warning by making sure the component is unmounted before the scheduled work finishes by manually calling But even better than an empty waitFor (which isn't a great solution because it's non-deterministic) is to have react-query expose some API that I can actually wait for. Something like: |
Hi @kentcdodds! You might be interested in this v3 change: 0f7c2af It adds the ability to wrap all React Query updates with a custom function, like |
That is interesting! Thanks for letting me know @boschni! What are the breaking changes looking like in v3? Is it going to be very impactful? |
No problem! It should be pretty easy to upgrade. A WIP guide can be found here: https://react-query-next.tanstack.com/guides/migrating-to-react-query-3 |
I'm finding I also have to beforeEach(async () => {
await waitFor(() => {});
});
afterEach(async () => {
queryCache.clear();
await waitFor(() => {});
}); |
I think I've finally fixed everything for my use cases. Here's what I've got: https://github.com/kentcdodds/bookshelf/blob/49d7bb9a706e7c0b63ab128c37e2b8a4bc20da3d/src/setupTests.js#L29-L52 Structuring things this way should make it so your tests will work with or without fake timers 🎉 🦸 |
This PR addresses three issues:
CancelledError
.CancelledError
aserror
to allow users to check if the query was cancelled (theisCancelledError
helper function can be used to check if an error is a cancelled error).