-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
test(react-query/useMutationState): clarify assertions and improve code formatting #9611
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(react-query/useMutationState): clarify assertions and improve code formatting #9611
Conversation
WalkthroughTest updates in packages/react-query/src/tests/useMutationState.test.tsx adjust timer advances, render timing, and assertions to capture mutation states over time. An array now records isMutating values per render, and tests validate intermediate and final sequences. Minor JSX formatting and assertion style updates are included. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
View your CI Pipeline Execution ↗ for commit 79b9ebf
☁️ Nx Cloud last updated this comment at |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9611 +/- ##
===========================================
+ Coverage 45.26% 84.51% +39.24%
===========================================
Files 208 26 -182
Lines 8340 368 -7972
Branches 1895 108 -1787
===========================================
- Hits 3775 311 -3464
+ Misses 4118 48 -4070
+ Partials 447 9 -438 🚀 New features to boost your workflow:
|
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.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/react-query/src/__tests__/useMutationState.test.tsx (1)
62-76
: Use prefix/suffix assertions instead of exact sequence to prevent flaky tests- await vi.advanceTimersByTimeAsync(41) - expect(isMutatingArray[0]).toEqual(0) - expect(isMutatingArray[1]).toEqual(1) - expect(isMutatingArray[2]).toEqual(2) - expect(isMutatingArray[3]).toEqual(1) - expect(isMutatingArray[4]).toEqual(0) - - expect(isMutatingArray).toEqual([0, 1, 2, 1, 0]) + await vi.advanceTimersByTimeAsync(41) + // Deterministic prefix/suffix; allow batching differences in the middle. + expect(isMutatingArray.slice(0, 3)).toEqual([0, 1, 2]) + expect([4, 5]).toContain(isMutatingArray.length) + expect(isMutatingArray.at(-1)).toEqual(0)
🧹 Nitpick comments (1)
packages/react-query/src/__tests__/useMutationState.test.tsx (1)
21-27
: Avoid side-effects in render; record values in an effectPushing to a shared array during render is a side-effect and can behave unexpectedly (e.g., extra renders). Record on value change via an effect instead.
function IsMutating() { const isMutating = useIsMutating() - - isMutatingArray.push(isMutating) - - return null + React.useEffect(() => { + isMutatingArray.push(isMutating) + }, [isMutating]) + return null }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/react-query/src/__tests__/useMutationState.test.tsx
(7 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/react-query/src/__tests__/useMutationState.test.tsx (2)
packages/vue-query/src/queryClient.ts (1)
isMutating
(53-55)packages/query-core/src/queryClient.ts (1)
isMutating
(116-120)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Preview
- GitHub Check: Test
🔇 Additional comments (2)
packages/react-query/src/__tests__/useMutationState.test.tsx (2)
173-177
: LGTM: custom queryClient pathUsing the queryClient param with plain render (no Provider) is correct, and the assertion reads clearly.
230-235
: LGTM: clearer presence assertionsSwitch to
toBeInTheDocument()
improves intent without changing semantics.
…assertions-improve-code-formatting
Summary by CodeRabbit