-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
test(query-core): add test case for queryClient.isFetching #8720
test(query-core): add test case for queryClient.isFetching #8720
Conversation
View your CI Pipeline Execution ↗ for commit 0156811.
☁️ Nx Cloud last updated this comment at |
queryFn: () => sleep(300).then(() => 'data'), | ||
}) | ||
expect(queryClient.isFetching()).toBe(1) | ||
queryClient.prefetchQuery({ | ||
queryKey: key2, | ||
queryFn: () => sleep(200).then(() => 'data'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we use real timers per default, please keep those times short (5ms and 10ms at most), or use fake timers and advance them how you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that I think about it, we’re actually having problems with these kinds of tests, as they tend to be pretty flaky (see useIsFetching). The reason is probably batching, and how much power the machine has / how much work it has to do, so it appears often in CI that updates are batched together.
using fake timers is better (we have an example for that in the code-base somewhere, too)
I agree, thanks for feedback!👍 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8720 +/- ##
===========================================
+ Coverage 46.31% 63.15% +16.83%
===========================================
Files 199 135 -64
Lines 7552 4855 -2697
Branches 1731 1368 -363
===========================================
- Hits 3498 3066 -432
+ Misses 3674 1544 -2130
+ Partials 380 245 -135 |
I reflected your review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move this to beforeAll / afterAll in the describe block:
beforeAll(() => {
vi.useFakeTimers()
})
afterAll(() => {
vi.useRealTimers()
})
otherwise, if the test fails, fake timers will be on and it will likely fail all other tests, which can be difficult to debug.
I reflect your review now in 0156811 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I thought you would limit it to the describe('isFetching', () => {
block, not the whole file 😅 . But this is great - we want to move everything to fake timers anyways, as they are faster and more reliable
No description provided.