Skip to content

test(query-devtools/contexts/QueryDevtoolsContext): add test for 'Provider' value reactivity via getter properties#10793

Merged
sukvvon merged 4 commits into
mainfrom
test/query-devtools-querydevtoolscontext-unit-tests
May 25, 2026
Merged

test(query-devtools/contexts/QueryDevtoolsContext): add test for 'Provider' value reactivity via getter properties#10793
sukvvon merged 4 commits into
mainfrom
test/query-devtools-querydevtoolscontext-unit-tests

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented May 25, 2026

🎯 Changes

Add a dedicated src/__tests__/contexts/QueryDevtoolsContext.test.tsx mirroring the src/contexts directory layout (matching the ThemeContext.test.tsx split from #10787).

The file locks down the one behavior that the module adds on top of solid-js's context primitives: a Provider value whose fields are reactive getters must propagate signal updates to consumers — the pattern that TanstackQueryDevtools uses (get client() { return client() }) to flow setClient / setTheme / setErrorTypes etc. into the rendered Devtools.

A bare value pass-through case and a default-value case were considered but dropped because they would only exercise solid-js itself, not anything the module contributes.

✅ 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 a test suite for QueryDevtoolsContext that verifies consumers observe reactive updates to the context's client, confirms the client value updates as expected, and ensures proper client cleanup after changes.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 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: a9e3c26c-41bc-45a9-b336-a63c547363af

📥 Commits

Reviewing files that changed from the base of the PR and between 3a3a2fe and 57e6e74.

📒 Files selected for processing (1)
  • packages/query-devtools/src/__tests__/contexts/QueryDevtoolsContext.test.tsx

📝 Walkthrough

Walkthrough

Adds a Vitest test that mounts a consumer under QueryDevtoolsContext.Provider and asserts useQueryDevtoolsContext() observes reactive updates to the provider’s client getter backed by a Solid signal.

Changes

QueryDevtoolsContext Hook Test

Layer / File(s) Summary
Reactive client observation test
packages/query-devtools/src/__tests__/contexts/QueryDevtoolsContext.test.tsx
Adds a Vitest test that renders QueryDevtoolsContext.Provider with a client getter backed by a Solid createSignal, consumes it via useQueryDevtoolsContext() and asserts ctx.client updates after the signal changes.

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs:

  • TanStack/query#10782: Adds devtools tests touching QueryDevtoolsContext and related devtools rendering behavior.

Suggested labels:
package: query-devtools

🐇 I hopped into tests with glee,
A provider, a signal, one, two, three,
The client flipped and then I saw,
The hook responded — neat and raw,
Devtools tested, carrot-cheer from me!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a test for QueryDevtoolsContext Provider value reactivity via getter properties.
Description check ✅ Passed The description follows the template, includes clear explanation of changes, completed checklist items, and correctly identifies this as a dev-only change requiring no changeset.
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-devtools-querydevtoolscontext-unit-tests

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

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 25, 2026

View your CI Pipeline Execution ↗ for commit 57e6e74

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

☁️ Nx Cloud last updated this comment at 2026-05-25 17:54:02 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 25, 2026

🚀 Changeset Version Preview

2 package(s) bumped directly, 23 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/lit-query 0.2.6 → 0.2.7 Changeset
@tanstack/query-devtools 5.100.14 → 5.100.15 Changeset
@tanstack/angular-query-experimental 5.100.14 → 5.100.15 Dependent
@tanstack/angular-query-persist-client 5.100.14 → 5.100.15 Dependent
@tanstack/eslint-plugin-query 5.100.14 → 5.100.15 Dependent
@tanstack/preact-query 5.100.14 → 5.100.15 Dependent
@tanstack/preact-query-devtools 5.100.14 → 5.100.15 Dependent
@tanstack/preact-query-persist-client 5.100.14 → 5.100.15 Dependent
@tanstack/query-async-storage-persister 5.100.14 → 5.100.15 Dependent
@tanstack/query-broadcast-client-experimental 5.100.14 → 5.100.15 Dependent
@tanstack/query-core 5.100.14 → 5.100.15 Dependent
@tanstack/query-persist-client-core 5.100.14 → 5.100.15 Dependent
@tanstack/query-sync-storage-persister 5.100.14 → 5.100.15 Dependent
@tanstack/react-query 5.100.14 → 5.100.15 Dependent
@tanstack/react-query-devtools 5.100.14 → 5.100.15 Dependent
@tanstack/react-query-next-experimental 5.100.14 → 5.100.15 Dependent
@tanstack/react-query-persist-client 5.100.14 → 5.100.15 Dependent
@tanstack/solid-query 5.100.14 → 5.100.15 Dependent
@tanstack/solid-query-devtools 5.100.14 → 5.100.15 Dependent
@tanstack/solid-query-persist-client 5.100.14 → 5.100.15 Dependent
@tanstack/svelte-query 6.1.33 → 6.1.34 Dependent
@tanstack/svelte-query-devtools 6.1.33 → 6.1.34 Dependent
@tanstack/svelte-query-persist-client 6.1.33 → 6.1.34 Dependent
@tanstack/vue-query 5.100.14 → 5.100.15 Dependent
@tanstack/vue-query-devtools 6.1.33 → 6.1.34 Dependent

@sukvvon sukvvon force-pushed the test/query-devtools-querydevtoolscontext-unit-tests branch 2 times, most recently from 80ec018 to 9922895 Compare May 25, 2026 17:28
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 (3)
packages/query-devtools/src/__tests__/contexts/QueryDevtoolsContext.test.tsx (3)

80-83: 💤 Low value

Optional: Strengthen assertions to verify the effect ran exactly twice.

While the current assertions correctly verify the observed client values, you could make the test more robust by confirming that createEffect ran exactly twice (once on mount, once after the signal update).

💡 Optional assertion improvements
-      expect(observed.at(-1)).toBe(initialClient)
+      expect(observed).toHaveLength(1)
+      expect(observed[0]).toBe(initialClient)
 
       setClient(nextClient)
-      expect(observed.at(-1)).toBe(nextClient)
+      expect(observed).toHaveLength(2)
+      expect(observed).toEqual([initialClient, nextClient])
🤖 Prompt for 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.

In `@packages/query-devtools/src/__tests__/contexts/QueryDevtoolsContext.test.tsx`
around lines 80 - 83, The test should assert that the effect ran exactly twice
by checking the observed array length in addition to the last values; update the
assertions around observed, setClient, and the signal update so you assert
observed.length (or use toHaveLength) equals 2 and that observed[0] is
initialClient and observed[1] (or at(-1)) is nextClient to ensure createEffect
executed once on mount and once after setClient.

53-54: ⚡ Quick win

Consider disposing QueryClient instances after use.

Both initialClient and nextClient should be disposed after the test completes to prevent potential resource leaks.

♻️ Suggested cleanup pattern
       expect(observed.at(-1)).toBe(initialClient)
 
       setClient(nextClient)
       expect(observed.at(-1)).toBe(nextClient)
+
+      initialClient.clear()
+      nextClient.clear()
     })
🤖 Prompt for 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.

In `@packages/query-devtools/src/__tests__/contexts/QueryDevtoolsContext.test.tsx`
around lines 53 - 54, The test creates two QueryClient instances (initialClient
and nextClient) but never disposes them; add cleanup to call their
disposal/cleanup methods (e.g., clear/destroy/cancel pending queries) after the
test completes—either in an afterEach block or a finally block inside the
test—so that initialClient and nextClient are cleaned up and no
resources/observers are leaked (locate the variables initialClient and
nextClient in QueryDevtoolsContext.test.tsx and invoke the appropriate disposal
method on each).

32-32: ⚡ Quick win

Consider disposing QueryClient instances after use.

QueryClient instances may hold resources such as caches and timers. While test instances are garbage-collected, explicitly disposing them is a best practice to prevent potential resource leaks in the test suite.

♻️ Suggested cleanup pattern
     it('should resolve to the value provided by the "Provider"', () => {
-      const value: QueryDevtoolsProps = {
-        client: new QueryClient(),
+      const client = new QueryClient()
+      const value: QueryDevtoolsProps = {
+        client,
         queryFlavor: 'TanStack Query',
         version: '5',
         onlineManager,
       }
       let resolved: QueryDevtoolsProps | undefined
       function ContextProbe() {
         resolved = useQueryDevtoolsContext()
         return null
       }
 
       render(() => (
         <QueryDevtoolsContext.Provider value={value}>
           <ContextProbe />
         </QueryDevtoolsContext.Provider>
       ))
 
       expect(resolved).toBe(value)
+      client.clear()
     })
🤖 Prompt for 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.

In `@packages/query-devtools/src/__tests__/contexts/QueryDevtoolsContext.test.tsx`
at line 32, The test creates a QueryClient instance (new QueryClient()) but
doesn't dispose it; update the test to store the instance in a variable and add
a teardown (e.g., afterEach) that properly cleans it up—call QueryClient methods
to cancel outstanding queries and clear caches (for example use
client.cancelQueries(), client.getQueryCache().clear(), and
client.getMutationCache().clear() or client.clear() if available) to ensure
QueryClient resources are released in the QueryDevtoolsContext.test.tsx tests.
🤖 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.

Nitpick comments:
In
`@packages/query-devtools/src/__tests__/contexts/QueryDevtoolsContext.test.tsx`:
- Around line 80-83: The test should assert that the effect ran exactly twice by
checking the observed array length in addition to the last values; update the
assertions around observed, setClient, and the signal update so you assert
observed.length (or use toHaveLength) equals 2 and that observed[0] is
initialClient and observed[1] (or at(-1)) is nextClient to ensure createEffect
executed once on mount and once after setClient.
- Around line 53-54: The test creates two QueryClient instances (initialClient
and nextClient) but never disposes them; add cleanup to call their
disposal/cleanup methods (e.g., clear/destroy/cancel pending queries) after the
test completes—either in an afterEach block or a finally block inside the
test—so that initialClient and nextClient are cleaned up and no
resources/observers are leaked (locate the variables initialClient and
nextClient in QueryDevtoolsContext.test.tsx and invoke the appropriate disposal
method on each).
- Line 32: The test creates a QueryClient instance (new QueryClient()) but
doesn't dispose it; update the test to store the instance in a variable and add
a teardown (e.g., afterEach) that properly cleans it up—call QueryClient methods
to cancel outstanding queries and clear caches (for example use
client.cancelQueries(), client.getQueryCache().clear(), and
client.getMutationCache().clear() or client.clear() if available) to ensure
QueryClient resources are released in the QueryDevtoolsContext.test.tsx tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 813ea494-6c04-4bc6-bc8f-d4114c367483

📥 Commits

Reviewing files that changed from the base of the PR and between 7252bdc and 6e943bc.

📒 Files selected for processing (1)
  • packages/query-devtools/src/__tests__/contexts/QueryDevtoolsContext.test.tsx

@sukvvon sukvvon self-assigned this May 25, 2026
…vider' value reactivity via getter properties
@sukvvon sukvvon force-pushed the test/query-devtools-querydevtoolscontext-unit-tests branch from b698ddd to 79e0b84 Compare May 25, 2026 17:30
@sukvvon sukvvon changed the title test(query-devtools/contexts/QueryDevtoolsContext): add unit test file mirroring the 'src/contexts' structure test(query-devtools/contexts/QueryDevtoolsContext): add test for 'Provider' value reactivity via getter properties May 25, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 25, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 57e6e74

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 25, 2026

size-limit report 📦

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

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-devtools/src/__tests__/contexts/QueryDevtoolsContext.test.tsx`:
- Around line 9-10: Add cleanup to avoid leaking QueryClient instances: in
QueryDevtoolsContext.test.tsx add an afterEach that calls initialClient.clear()
and nextClient.clear() (or the appropriate QueryClient disposal method if using
a different version) to dispose both QueryClient instances created as
initialClient and nextClient so they don't accumulate across tests.
🪄 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: 1bf27ca6-ab2a-4768-a2fd-f1c8cfe6b9ca

📥 Commits

Reviewing files that changed from the base of the PR and between 6e943bc and 3a3a2fe.

📒 Files selected for processing (1)
  • packages/query-devtools/src/__tests__/contexts/QueryDevtoolsContext.test.tsx

@sukvvon sukvvon merged commit 828858d into main May 25, 2026
9 checks passed
@sukvvon sukvvon deleted the test/query-devtools-querydevtoolscontext-unit-tests branch May 25, 2026 17:54
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