-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
test(react-query/HydrationBoundary): add tests for 'non-object' state and missing 'queries' property handling #9605
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
Conversation
… and missing 'queries' property handling
WalkthroughAdds two tests to HydrationBoundary.test.tsx to ensure no hydration occurs when provided state is non-object or lacks a queries property, using a mocked hydrate call and timer advancement within a QueryClientProvider setup. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ 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 1fe93b6
☁️ Nx Cloud last updated this comment at |
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
🧹 Nitpick comments (1)
packages/react-query/src/__tests__/HydrationBoundary.test.tsx (1)
365-387
: Minor cleanups for clarity and resilience
- Prefer
expect(hydrateSpy).not.toHaveBeenCalled()
overtoHaveBeenCalledTimes(0)
.vi.advanceTimersByTimeAsync(0)
isn’t needed; hydration would be synchronous if it happened.- Use try/finally to always restore the spy and clear the client even if an assertion fails.
- Optional: rename the second test to be more explicit, e.g., “should not hydrate queries if state.queries is missing”.
Apply diffs:
@@ - test('should not hydrate queries if state is not an object', async () => { + test('should not hydrate queries if state is not an object', async () => { const queryClient = new QueryClient() const hydrateSpy = vi.spyOn(coreModule, 'hydrate') - function Page() { - return null - } - - render( - <QueryClientProvider client={queryClient}> - <HydrationBoundary state={'invalid-state' as any}> - <Page /> - </HydrationBoundary> - </QueryClientProvider>, - ) - - await vi.advanceTimersByTimeAsync(0) - expect(hydrateSpy).toHaveBeenCalledTimes(0) - - hydrateSpy.mockRestore() - queryClient.clear() + try { + function Page() { + return null + } + render( + <QueryClientProvider client={queryClient}> + <HydrationBoundary state={'invalid-state' as any}> + <Page /> + </HydrationBoundary> + </QueryClientProvider>, + ) + expect(hydrateSpy).not.toHaveBeenCalled() + } finally { + hydrateSpy.mockRestore() + queryClient.clear() + } }) @@ - test('should handle state without queries property gracefully', async () => { + test('should not hydrate queries if state.queries is missing', async () => { const queryClient = new QueryClient() const hydrateSpy = vi.spyOn(coreModule, 'hydrate') - function Page() { - return null - } - - render( - <QueryClientProvider client={queryClient}> - <HydrationBoundary state={{} as any}> - <Page /> - </HydrationBoundary> - </QueryClientProvider>, - ) - - await vi.advanceTimersByTimeAsync(0) - expect(hydrateSpy).toHaveBeenCalledTimes(0) - - hydrateSpy.mockRestore() - queryClient.clear() + try { + function Page() { + return null + } + render( + <QueryClientProvider client={queryClient}> + <HydrationBoundary state={{} as any}> + <Page /> + </HydrationBoundary> + </QueryClientProvider>, + ) + expect(hydrateSpy).not.toHaveBeenCalled() + } finally { + hydrateSpy.mockRestore() + queryClient.clear() + } })Also applies to: 389-411
📜 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__/HydrationBoundary.test.tsx
(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/react-query/src/__tests__/HydrationBoundary.test.tsx (1)
packages/react-query/src/HydrationBoundary.tsx (1)
HydrationBoundary
(25-108)
⏰ 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). (3)
- GitHub Check: autofix
- GitHub Check: Preview
- GitHub Check: Test
🔇 Additional comments (2)
packages/react-query/src/__tests__/HydrationBoundary.test.tsx (2)
365-387
: LGTM: Correctly asserts no hydration for non-object stateThis matches HydrationBoundary’s guard (typeof state !== 'object' → early return), so hydrate should never be called.
389-411
: LGTM: Covers missingqueries
property pathState fallback to
queries || []
means no hydration; this test validates that path.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9605 +/- ##
===========================================
+ Coverage 45.21% 84.51% +39.29%
===========================================
Files 208 26 -182
Lines 8335 368 -7967
Branches 1889 108 -1781
===========================================
- Hits 3769 311 -3458
+ Misses 4119 48 -4071
+ Partials 447 9 -438 🚀 New features to boost your workflow:
|
AS-IS
TO-BE
Summary by CodeRabbit