Uh oh!
There was an error while loading. Please reload this page.
test(query-core): assert exact cache event payloads in subscribe callbacks - #11053
Conversation
View your CI Pipeline Execution ↗ for commit 971cf30
☁️ Nx Cloud last updated this comment at |
📝 WalkthroughWalkthroughThe PR strengthens query-core cache subscription tests by asserting complete event payloads, including event type and the associated mutation, query, or observer. ChangesCache notification tests
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 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. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@packages/query-core/src/__tests__/queryClient.test.tsx`:
- Around line 1617-1620: Update the callback assertion in the queryCache event
test to verify the emitted reset action alongside type and query. Extend the
expect.objectContaining payload for the updated event with the expected reset
action, preserving the existing query assertion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b62d349c-7490-446d-80ef-365de705030f
📒 Files selected for processing (5)
packages/query-core/src/__tests__/mutationCache.test.tsxpackages/query-core/src/__tests__/query.test.tsxpackages/query-core/src/__tests__/queryCache.test.tsxpackages/query-core/src/__tests__/queryClient.test.tsxpackages/query-core/src/__tests__/queryObserver.test.tsx
Uh oh!
There was an error while loading. Please reload this page.
size-limit report 📦
|
e689aa7 to
cd7feebComparecd7feeb to
d31ecb5Compared31ecb5 to
971cf30CompareUh oh!
There was an error while loading. Please reload this page.
🎯 Changes
QueryCache/MutationCachesubscribe callbacks receive an event object whosequery/mutationis an instance the library creates internally. Several tests only checked that the callback fired (toHaveBeenCalled()) or matched thetypefield partially (objectContaining), leaving the instance and the exact payload shape unverified.Each test can recover the instance from the cache (
find({ queryKey }), or the in-scopemutation/observer), so the assertions now pin the full event object. Where the callback fires multiple times in a known order, the assertion is also pinned to the right call (addedis the first event,removedfrom gc is the last).queryCache—addedevents (4 tests) — asserttoHaveBeenNthCalledWith(1, { query, type: 'added' });addedis always the first event, and the earliertoHaveBeenCalledWith/toHaveBeenCalled()did not pin the call positionmutationCache— "should still notify removal..." — droppedobjectContainingso{ type: 'removed', mutation }also asserts no extra fields (single call is already guaranteed bytoHaveBeenCalledTimes(1))query— "queries should be garbage collected even if they never fetched" — captures the query before gc removes it, then assertstoHaveBeenLastCalledWith({ type: 'removed', query })(gc removal is the last event)queryObserver— "should notify cache listeners when setOptions is called" — asserts the full{ type: 'observerOptionsUpdated', query, observer }(single call is already guaranteed bytoHaveBeenCalledTimes(1))queryClient— "should notify listeners when a query is reset" —toHaveBeenCalled()→toHaveBeenNthCalledWith(1, objectContaining({ type: 'updated', query, action: { type: 'setState' } }))(theaction.statesnapshot is left open, as it depends on timing)✅ Checklist
🚀 Release Impact
Summary by CodeRabbit