Skip to content

test(query-core/subscribable): add unit tests for the Subscribable base class - #11364

Open
solssak wants to merge 1 commit into
TanStack:mainfrom
solssak:test/query-core-subscribable
Open

test(query-core/subscribable): add unit tests for the Subscribable base class#11364
solssak wants to merge 1 commit into
TanStack:mainfrom
solssak:test/query-core-subscribable

Conversation

@solssak

@solssak solssak commented Sep 2, 2026

Copy link
Copy Markdown

🎯 Changes

Add a dedicated unit test file for the Subscribable base class in query-core.

Subscribable is the base class that QueryCache, MutationCache, QueryObserver, MutationObserver, QueriesObserver, FocusManager, and OnlineManager all extend, but it had no test file of its own — its behavior was only exercised indirectly through those subclasses. This PR tests the class directly so the core subscribe/unsubscribe contract is pinned down in one place.

The new subscribable.test.tsx uses a minimal test subclass that spies on the protected onSubscribe/onUnsubscribe hooks, and covers:

  • onSubscribe fires once per subscribe() call
  • onUnsubscribe fires when the returned unsubscribe function is called
  • hasListeners() transitions correctly across subscribe/unsubscribe, including when multiple listeners are registered and only some unsubscribe
  • the same listener reference is de-duplicated (the underlying Set semantics)
  • the subscribe method stays bound to the instance when destructured (the this.subscribe = this.subscribe.bind(this) in the constructor)

No source code is changed — this only adds test coverage.

✅ Checklist

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

🚀 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 comprehensive coverage for subscription behavior, including listener lifecycle hooks, listener state tracking, duplicate listener handling, and stable subscription references.

@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 112665cb-aae7-4919-9239-e26d978cffbe

📥 Commits

Reviewing files that changed from the base of the PR and between 40cb38d and c29253d.

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

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Added a new Subscribable test suite. The tests cover lifecycle hooks, listener state, duplicate listener references, and destructured subscribe calls.

Changes

Subscribable listener lifecycle

Layer / File(s) Summary
Listener lifecycle and state tests
packages/query-core/src/__tests__/subscribable.test.tsx
Defines lifecycle hook spies and tests subscription, unsubscription, hasListeners(), listener deduplication, and stable destructured subscribe behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to c2925

This change adds focused tests for existing subscription behavior without modifying production code or runtime behavior. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the addition of unit tests for the query-core Subscribable base class.
Description check ✅ Passed The description explains the change, motivation, test coverage, checklist status, and release impact. It matches the required template and confirms that no source code changes are included.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
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.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1 files.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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