Skip to content

test(query-core/queriesObserver): add test for skipping 'trackResult' when 'notifyOnChangeProps' is set#10512

Merged
sukvvon merged 1 commit intomainfrom
test/query-core-queriesObserver-notifyOnChangeProps
Apr 18, 2026
Merged

test(query-core/queriesObserver): add test for skipping 'trackResult' when 'notifyOnChangeProps' is set#10512
sukvvon merged 1 commit intomainfrom
test/query-core-queriesObserver-notifyOnChangeProps

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Apr 18, 2026

🎯 Changes

Add a test to verify that #trackResult returns the observer result directly (without calling trackResult) when notifyOnChangeProps is set on the query options.

This covers the else branch of !notifyOnChangeProps ? trackResult(...) : observerResult in #trackResult.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Tests
    • Enhanced test coverage for query observer optimization behavior to ensure accurate result tracking under specific notification conditions.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 18, 2026

📝 Walkthrough

Walkthrough

A new test case is added to QueriesObserver.test.tsx that verifies QueriesObserver.getOptimisticResult returns proxy/observer results directly when notifyOnChangeProps: ['data'] is configured. The test uses a spy on QueryObserver.prototype.trackResult to validate tracking behavior.

Changes

Cohort / File(s) Summary
Test Updates
packages/query-core/src/__tests__/queriesObserver.test.tsx
Added test case asserting getOptimisticResult returns results directly via trackResult when notifyOnChangeProps is set, with spy verification that trackResult behaves as expected during tracking.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

package: query-core

Poem

🐰 A test hops forth with watchful eyes,
Tracking props through queries wise,
Direct results, no trackResult fuss,
QueriesObserver trusts in us! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the test addition, focusing on the key behavior being tested (skipping trackResult when notifyOnChangeProps is set).
Description check ✅ Passed The description follows the template structure with complete sections, clearly explains the change and its purpose, and includes all required checklist items and release impact information.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/query-core-queriesObserver-notifyOnChangeProps

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Apr 18, 2026

View your CI Pipeline Execution ↗ for commit e605f9f

Command Status Duration Result
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 2s View ↗
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 3m 49s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-18 00:06:34 UTC

@github-actions
Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/query-core/src/__tests__/queriesObserver.test.tsx (1)

622-631: Strengthen the test by asserting reference identity, not just call count.

You already verify trackResult is not invoked, but the test name/intent also says the observer result is returned directly. Please assert that trackedResults[0] is the exact same object as the raw optimistic result entry.

Suggested diff
-    const [, , trackResult] = observer.getOptimisticResult(
+    const [rawResults, , trackResult] = observer.getOptimisticResult(
       [{ queryKey: key, queryFn, notifyOnChangeProps: ['data'] }],
       undefined,
     )
 
     const trackedResults = trackResult()
 
     expect(trackedResults).toHaveLength(1)
+    expect(trackedResults[0]).toBe(rawResults[0])
     // trackResult should NOT be called when notifyOnChangeProps is set
     expect(trackResultSpy).not.toHaveBeenCalled()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/query-core/src/__tests__/queriesObserver.test.tsx` around lines 622
- 631, Destructure the optimistic results from observer.getOptimisticResult so
you can assert identity rather than only call count: change the destructuring to
capture the first return value (e.g. const [optimisticResults, , trackResult] =
observer.getOptimisticResult(...)) and after calling trackResult() add an
assertion expect(trackedResults[0]).toBe(optimisticResults[0]) to verify the
returned trackedResults entry is the exact same object as the raw optimistic
result; use the existing symbols observer.getOptimisticResult, trackResult,
trackedResults, trackResultSpy, key, queryFn, and notifyOnChangeProps to locate
the test code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/query-core/src/__tests__/queriesObserver.test.tsx`:
- Around line 622-631: Destructure the optimistic results from
observer.getOptimisticResult so you can assert identity rather than only call
count: change the destructuring to capture the first return value (e.g. const
[optimisticResults, , trackResult] = observer.getOptimisticResult(...)) and
after calling trackResult() add an assertion
expect(trackedResults[0]).toBe(optimisticResults[0]) to verify the returned
trackedResults entry is the exact same object as the raw optimistic result; use
the existing symbols observer.getOptimisticResult, trackResult, trackedResults,
trackResultSpy, key, queryFn, and notifyOnChangeProps to locate the test code.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 329007f6-2b3e-456a-9004-76830e7e8003

📥 Commits

Reviewing files that changed from the base of the PR and between 658d32b and e605f9f.

📒 Files selected for processing (1)
  • packages/query-core/src/__tests__/queriesObserver.test.tsx

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 18, 2026

More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@10512

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@10512

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@10512

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/@tanstack/preact-query-devtools@10512

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@10512

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@10512

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@10512

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@10512

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@10512

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@10512

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@10512

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@10512

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@10512

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@10512

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@10512

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@10512

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@10512

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@10512

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@10512

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@10512

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@10512

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@10512

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@10512

commit: e605f9f

@github-actions
Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
react full 11.99 KB (0%)
react minimal 9.02 KB (0%)

@sukvvon sukvvon self-assigned this Apr 18, 2026
@sukvvon sukvvon merged commit cc97e9a into main Apr 18, 2026
10 checks passed
@sukvvon sukvvon deleted the test/query-core-queriesObserver-notifyOnChangeProps branch April 18, 2026 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant