test(react-query-devtools): extract shared test setup into 'beforeEach'#11026
Conversation
|
View your CI Pipeline Execution ↗ for commit 3209261
☁️ Nx Cloud last updated this comment at |
📝 WalkthroughWalkthroughTest files for ReactQueryDevtools and ReactQueryDevtoolsPanel are refactored to use shared ChangesDevtools test suite refactor and coverage expansion
Estimated code review effort: 2 (Simple) | ~12 minutes Sequence Diagram(s)sequenceDiagram
participant Test
participant ReactQueryDevtools
participant DevtoolsInstance
Test->>ReactQueryDevtools: render with props (buttonPosition, position, initialIsOpen, errorTypes, theme)
ReactQueryDevtools->>DevtoolsInstance: mount
Test->>ReactQueryDevtools: rerender with changed props
ReactQueryDevtools->>DevtoolsInstance: setButtonPosition / setPosition / setInitialIsOpen / setErrorTypes / setTheme
Test->>ReactQueryDevtools: unmount
ReactQueryDevtools->>DevtoolsInstance: unmount
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
🚀 Changeset Version PreviewNo changeset entries found. Merging this PR will not cause a version bump for any packages. |
size-limit report 📦
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/react-query-devtools/src/__tests__/ReactQueryDevtoolsPanel.test.tsx (1)
54-75: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider strengthening the "default onClose" assertion.
The default-onClose test (lines 69-73) only checks
expect.any(Function), which would pass even if the wrong function were forwarded. SincesetOnClosealways receives a wrapped closure (props.onClose ?? (() => {})), you could invoke the captured argument to assert it doesn't throw and returnsundefined, giving stronger confidence it's actually a no-op.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/react-query-devtools/src/__tests__/ReactQueryDevtoolsPanel.test.tsx` around lines 54 - 75, The default onClose test in ReactQueryDevtoolsPanel is too weak because it only verifies that setOnCloseMock receives any function. Update the test around ReactQueryDevtoolsPanel and setOnCloseMock to capture the forwarded callback, invoke it, and assert it does not throw and returns undefined so you verify the omitted-prop path באמת uses the no-op closure from props.onClose ?? (() => {}).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@packages/react-query-devtools/src/__tests__/ReactQueryDevtoolsPanel.test.tsx`:
- Around line 54-75: The default onClose test in ReactQueryDevtoolsPanel is too
weak because it only verifies that setOnCloseMock receives any function. Update
the test around ReactQueryDevtoolsPanel and setOnCloseMock to capture the
forwarded callback, invoke it, and assert it does not throw and returns
undefined so you verify the omitted-prop path באמת uses the no-op closure from
props.onClose ?? (() => {}).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ad6d8ffd-ccfe-48e9-bb2c-cb727aba318f
📒 Files selected for processing (2)
packages/react-query-devtools/src/__tests__/ReactQueryDevtools.test.tsxpackages/react-query-devtools/src/__tests__/ReactQueryDevtoolsPanel.test.tsx
🎯 Changes
Removes the boilerplate repeated in every test of
ReactQueryDevtoolsandReactQueryDevtoolsPanelby hoisting the shared setup intobeforeEach:await import(...)of the component andconst queryClient = new QueryClient()were duplicated in each test. They now live in a singlebeforeEach, exposed vialetbindings.awaitanything drop their needlessasync.return null) test keeps its ownimport('..')aftervi.resetModules()and renames the binding toProductionDevtools/ProductionDevtoolsPanelto avoid shadowing.No test behavior changes; all existing assertions are preserved.
✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit