Skip to content

test(query-core/queryObserver): add tests for 'notifyOnChangeProps' as a function controlling listener notification#10900

Merged
sukvvon merged 2 commits into
mainfrom
test/query-core-query-observer-notify-on-change-props-function
Jun 7, 2026
Merged

test(query-core/queryObserver): add tests for 'notifyOnChangeProps' as a function controlling listener notification#10900
sukvvon merged 2 commits into
mainfrom
test/query-core-query-observer-notify-on-change-props-function

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Jun 7, 2026

🎯 Changes

Adds two tests in queryObserver.test.tsx covering the function form of notifyOnChangeProps.

queryObserver.test.tsx previously had no notifyOnChangeProps tests at all. These verify that when notifyOnChangeProps is a function, its returned value controls whether listeners are notified:

  • listeners are notified when a returned prop (data) changes
  • listeners are not notified when a returned prop (data) does not change

This covers the previously uncovered branch in shouldNotifyListeners where notifyOnChangeProps is called as a function.

✅ 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
    • Added tests verifying observer listeners trigger when a function-based change detector reports an actual data change after a refetch.
    • Added tests ensuring listeners are not triggered when the detector reports no meaningful data change after a refetch.
    • Tests use controlled timing to validate listener invocation behavior across refetch scenarios.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 7, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fb64aec2-b1e7-4abb-9ed8-5392493d8bcb

📥 Commits

Reviewing files that changed from the base of the PR and between 03f6585 and fc9e160.

📒 Files selected for processing (1)
  • packages/query-core/src/__tests__/queryObserver.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/query-core/src/tests/queryObserver.test.tsx

📝 Walkthrough

Walkthrough

This PR adds two tests to queryObserver.test.tsx exercising notifyOnChangeProps when it's a function: one asserts the listener is called after refetch when data changes, the other asserts the listener is not called when data remains identical.

Changes

notifyOnChangeProps function test coverage

Layer / File(s) Summary
notifyOnChangeProps function test cases
packages/query-core/src/__tests__/queryObserver.test.tsx
Two async tests create a QueryObserver with notifyOnChangeProps as a function, seed cached data, perform observer.refetch() with delayed results, and assert the subscription listener is called when data changes and not called when data stays the same.

🎯 2 (Simple) | ⏱️ ~10 minutes

  • TanStack/query#10899: Related test additions around function-valued callbacks in queryObserver test coverage.

"I am a rabbit in the test-green wood,
Timers set, I watch refetches brood,
One hop of data, the listener sings,
One still step, and silent rings,
I nibble assertions—tests behaved as they should."

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding tests for the function form of 'notifyOnChangeProps' and its behavior in controlling listener notifications.
Description check ✅ Passed The description covers all required template sections with clear explanations of changes, completed checklist items, and appropriate release impact marking.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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-query-observer-notify-on-change-props-function

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

@sukvvon sukvvon self-assigned this Jun 7, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jun 7, 2026

View your CI Pipeline Execution ↗ for commit fc9e160

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

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-07 07:31:38 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 7, 2026

🚀 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.

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__/queryObserver.test.tsx`:
- Around line 750-764: The test is asserting on the listener's total call
history which can be polluted by earlier notifications; after creating the mock
listener (vi.fn()) and subscribing with observer.subscribe(listener), call
listener.mockClear() (or listener.mockReset()) before triggering
observer.refetch() so the assertion checks only notifications caused by refetch;
update both tests that use QueryObserver.subscribe(listener) +
observer.refetch() to clear the mock after subscribe and before the
refetch/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: 5ce13e5d-fd83-4a93-8f2c-024d04417725

📥 Commits

Reviewing files that changed from the base of the PR and between 413fdc5 and 450047c.

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

Comment thread packages/query-core/src/__tests__/queryObserver.test.tsx
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 7, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@10900

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: fc9e160

@sukvvon sukvvon force-pushed the test/query-core-query-observer-notify-on-change-props-function branch from 450047c to 5bdc383 Compare June 7, 2026 07:02
…s a function controlling listener notification
@sukvvon sukvvon force-pushed the test/query-core-query-observer-notify-on-change-props-function branch from 5bdc383 to 03f6585 Compare June 7, 2026 07:06
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 7, 2026

size-limit report 📦

Path Size
react full 12.11 KB (0%)
react minimal 9.08 KB (0%)

…nge-props-function

# Conflicts:
#	packages/query-core/src/__tests__/queryObserver.test.tsx
@sukvvon sukvvon merged commit 4077908 into main Jun 7, 2026
9 checks passed
@sukvvon sukvvon deleted the test/query-core-query-observer-notify-on-change-props-function branch June 7, 2026 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant