Skip to content

test(query-core/queriesObserver): add test for subscribing new observers when a query is added while subscribed#10246

Open
sukvvon wants to merge 2 commits intoTanStack:mainfrom
sukvvon:test/query-core-queriesObserver-subscribe-new-observer
Open

test(query-core/queriesObserver): add test for subscribing new observers when a query is added while subscribed#10246
sukvvon wants to merge 2 commits intoTanStack:mainfrom
sukvvon:test/query-core-queriesObserver-subscribe-new-observer

Conversation

@sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Mar 6, 2026

🎯 Changes

Add a test for queriesObserver.ts lines 150-151 — subscribing new observers when setQueries adds a query while the QueriesObserver already has listeners.

The test verifies that when a new query is added via setQueries during an active subscription, the new observer is automatically subscribed and its fetch result is properly propagated through #onUpdate to the listener.

✅ 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 test coverage for dynamic query additions to the observer, including verification that async query results are properly included in subscription updates.

@changeset-bot
Copy link

changeset-bot bot commented Mar 6, 2026

⚠️ No Changeset found

Latest commit: 1842ae3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8c9be809-2f57-4770-87e7-3d5a752a90d5

📥 Commits

Reviewing files that changed from the base of the PR and between fe25edc and 0d0a0a4.

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

📝 Walkthrough

Walkthrough

This PR adds a test to QueriesObserver that verifies correct behavior when new queries are dynamically added to an observer after initial subscription, including handling of delayed async resolvers. The test confirms all queries' results are properly emitted.

Changes

Cohort / File(s) Summary
Test Addition
packages/query-core/src/__tests__/queriesObserver.test.tsx
New test case verifying QueriesObserver correctly emits results from dynamically added queries, including delayed async queries. Establishes initial subscriptions, updates observer with additional query containing 10ms delay, and asserts final results contain data from all three queries.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A test hops in, so crisp and clean,
Observers dance with queries unseen,
Add them quick, or add them slow,
Results still bloom—off we go! 🌱✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: adding a test for subscribing new observers when a query is added while the QueriesObserver is subscribed.
Description check ✅ Passed The description follows the template structure and includes all required sections with complete information about the changes, testing, and release impact assessment.
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 unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@nx-cloud
Copy link

nx-cloud bot commented Mar 6, 2026

View your CI Pipeline Execution ↗ for commit 1842ae3

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

☁️ Nx Cloud last updated this comment at 2026-03-06 02:17:39 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 6, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: af03389

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