Skip to content

test(query-devtools/DevtoolsPanelComponent): add tests for rendering without throwing, panel-only mode, and 'onClose' prop#10680

Merged
sukvvon merged 1 commit into
mainfrom
test/query-devtools-devtools-panel-component
May 9, 2026
Merged

test(query-devtools/DevtoolsPanelComponent): add tests for rendering without throwing, panel-only mode, and 'onClose' prop#10680
sukvvon merged 1 commit into
mainfrom
test/query-devtools-devtools-panel-component

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented May 9, 2026

🎯 Changes

Add tests for DevtoolsPanelComponent, the lightweight wrapper used by TanstackQueryDevtoolsPanel to render the devtools as a panel-only mode.

  • Verifies the component mounts without throwing.
  • Verifies the open devtools button is not rendered in panel-only mode.
  • Verifies the onClose prop is invoked when the close button is clicked.

Reuses the same mocks and stubs as DevtoolsComponent.test.tsx:

  • solid-transition-group mock to bypass a transitive @solid-primitives/transition-group exports field that Vite cannot resolve.
  • goober mock to avoid heavy css template compilation on each mount.
  • localStorage, matchMedia, ResizeObserver stubs.

✅ 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
    • Expanded Devtools panel test suite to verify rendering, panel-only mode hides the open control, the close control calls its callback, and test isolation/cleanup is ensured between runs.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 2026

📝 Walkthrough

Walkthrough

Adds a Vitest test file for DevtoolsPanelComponent that mocks modules, stubs browser globals and ResizeObserver, sets up/tears down a QueryClient per test, and includes render, panel-only absence, and onClose behavior tests.

Changes

DevtoolsPanelComponent Test Suite

Layer / File(s) Summary
Test imports and tooling
packages/query-devtools/src/__tests__/DevtoolsPanelComponent.test.tsx
Adds Vitest imports, testing utilities, and module mocks (solid-transition-group, goober).
Suite state declarations
packages/query-devtools/src/__tests__/DevtoolsPanelComponent.test.tsx
Declares in-memory storage, queryClient variable, and previous document root font size.
beforeEach: stub globals & init QueryClient
packages/query-devtools/src/__tests__/DevtoolsPanelComponent.test.tsx
Stubs localStorage, matchMedia, ResizeObserver with in-memory implementations and creates a fresh QueryClient; sets root font size.
afterEach: restore and clear
packages/query-devtools/src/__tests__/DevtoolsPanelComponent.test.tsx
Restores original globals, clears in-memory storage, calls queryClient.clear(), and restores document root font size.
Render test (no throw)
packages/query-devtools/src/__tests__/DevtoolsPanelComponent.test.tsx
Renders component with required props and asserts mounting does not throw.
Panel-only absence check
packages/query-devtools/src/__tests__/DevtoolsPanelComponent.test.tsx
Renders in panel-only configuration and asserts the "Open Tanstack query devtools" control is not rendered.
onClose click behavior
packages/query-devtools/src/__tests__/DevtoolsPanelComponent.test.tsx
Renders with an onClose spy, clicks close button via accessible label, and asserts onClose was invoked.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • TanStack/query#10679: Adds similar Vitest tests and mocks for query-devtools components; closely related test changes.

Poem

🐰 I hopped into tests with a gentle twitch,
Stubbing globals softly to scratch an itch.
Rendered the panel, checked a missing control,
Clicked the close button, it answered my call.
A rabbit's quick test — tidy, light, and small.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description follows the template structure with detailed changes, completed checklist items, and proper release impact classification as dev-only.
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.
Title check ✅ Passed The title accurately summarizes the main change: adding tests for DevtoolsPanelComponent covering rendering, panel-only mode, and onClose prop functionality, which aligns with the changeset.

✏️ 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-devtools-panel-component

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

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 9, 2026

View your CI Pipeline Execution ↗ for commit 537f542

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

☁️ Nx Cloud last updated this comment at 2026-05-09 19:56:53 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

🚀 Changeset Version Preview

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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 9, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 4218586

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

size-limit report 📦

Path Size
react full 12.1 KB (0%)
react minimal 9.07 KB (0%)

@sukvvon sukvvon force-pushed the test/query-devtools-devtools-panel-component branch from 537f542 to bb91f7f Compare May 9, 2026 19:36
@sukvvon sukvvon changed the title test(query-devtools/DevtoolsPanelComponent): add tests for panel-only mode and 'onClose' prop test(query-devtools/DevtoolsPanelComponent): add tests for rendering without throwing and 'onClose' prop May 9, 2026
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-devtools/src/__tests__/DevtoolsPanelComponent.test.tsx (1)

71-75: 💤 Low value

Optional: Remove redundant storage clear.

Line 73 manually clears storage, but this is unnecessary because:

  • Line 72 already unstubs all globals (removing the localStorage stub)
  • The next beforeEach creates a fresh storage object
  • The manual clear provides no additional cleanup benefit
♻️ Optional cleanup simplification
 afterEach(() => {
   vi.unstubAllGlobals()
-  Object.keys(storage).forEach((key) => delete storage[key])
   queryClient.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__/DevtoolsPanelComponent.test.tsx` around
lines 71 - 75, The afterEach cleanup contains a redundant manual clear of the
test storage: remove the Object.keys(storage).forEach((key) => delete
storage[key]) line because vi.unstubAllGlobals() already removes the
localStorage stub and the next beforeEach recreates storage; keep
vi.unstubAllGlobals() and queryClient.clear() in the afterEach to preserve
necessary teardown for the tests referencing storage and queryClient.
🤖 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__/DevtoolsPanelComponent.test.tsx`:
- Around line 71-75: The afterEach cleanup contains a redundant manual clear of
the test storage: remove the Object.keys(storage).forEach((key) => delete
storage[key]) line because vi.unstubAllGlobals() already removes the
localStorage stub and the next beforeEach recreates storage; keep
vi.unstubAllGlobals() and queryClient.clear() in the afterEach to preserve
necessary teardown for the tests referencing storage and queryClient.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a5bf482c-d009-4ab0-879a-de86b2655f22

📥 Commits

Reviewing files that changed from the base of the PR and between b79d7b4 and 537f542.

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

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: 2

🤖 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__/DevtoolsPanelComponent.test.tsx`:
- Around line 77-88: The test for DevtoolsPanelComponent currently only verifies
rendering and onClose behavior but doesn't assert that the "open devtools"
button is absent in panel-only mode; update the test in
DevtoolsPanelComponent.test.tsx (the it block that renders
<DevtoolsPanelComponent ... />) to explicitly query for the open-button (e.g.,
by its visible text "Open devtools" or its accessible role/label) using the
renderer's queryByText/queryByRole and assert that it is not present (null /
notInTheDocument) after render to ensure panel-only mode hides that button.
- Around line 68-75: The test mutates document.documentElement.style.fontSize in
the setup but never restores it, which can leak into other tests; fix by
capturing the original font-size (e.g., const originalRootFontSize =
document.documentElement.style.fontSize) in the beforeEach where
document.documentElement.style.fontSize = '16px' is set and then restore it in
the afterEach (alongside vi.unstubAllGlobals()/storage
cleanup/queryClient.clear()) by reassigning
document.documentElement.style.fontSize = originalRootFontSize so the global DOM
style is returned to its previous state after each test.
🪄 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: 113da576-ad99-4802-a3d3-364e2d786169

📥 Commits

Reviewing files that changed from the base of the PR and between 537f542 and bb91f7f.

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

@sukvvon sukvvon force-pushed the test/query-devtools-devtools-panel-component branch from bb91f7f to efa4a07 Compare May 9, 2026 19:41
@sukvvon sukvvon changed the title test(query-devtools/DevtoolsPanelComponent): add tests for rendering without throwing and 'onClose' prop test(query-devtools/DevtoolsPanelComponent): add tests for panel-only mode and 'onClose' prop May 9, 2026
@sukvvon sukvvon self-assigned this May 9, 2026
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-devtools/src/__tests__/DevtoolsPanelComponent.test.tsx (1)

120-123: ⚡ Quick win

Strengthen close-handler assertion to catch duplicate emissions.

At Line 122, toHaveBeenCalled() passes even if one click triggers multiple callbacks. Prefer an exact count.

Proposed tweak
-    expect(onClose).toHaveBeenCalled()
+    expect(onClose).toHaveBeenCalledTimes(1)
🤖 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__/DevtoolsPanelComponent.test.tsx` around
lines 120 - 123, The test currently uses a loose assertion
expect(onClose).toHaveBeenCalled() which won't catch duplicate emissions from
the click; update the assertion in DevtoolsPanelComponent.test.tsx to assert the
exact call count for the onClose mock (use
expect(onClose).toHaveBeenCalledTimes(1)) and, to be safer, assert it was not
called before the click (expect(onClose).not.toHaveBeenCalled()) so a single
click must produce exactly one invocation.
🤖 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__/DevtoolsPanelComponent.test.tsx`:
- Around line 120-123: The test currently uses a loose assertion
expect(onClose).toHaveBeenCalled() which won't catch duplicate emissions from
the click; update the assertion in DevtoolsPanelComponent.test.tsx to assert the
exact call count for the onClose mock (use
expect(onClose).toHaveBeenCalledTimes(1)) and, to be safer, assert it was not
called before the click (expect(onClose).not.toHaveBeenCalled()) so a single
click must produce exactly one invocation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8d903886-69dc-46ad-8c75-06914f5045d6

📥 Commits

Reviewing files that changed from the base of the PR and between bb91f7f and efa4a07.

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

@sukvvon sukvvon force-pushed the test/query-devtools-devtools-panel-component branch from efa4a07 to 587be3e Compare May 9, 2026 19:48
…without throwing, panel-only mode, and 'onClose' prop
@sukvvon sukvvon force-pushed the test/query-devtools-devtools-panel-component branch from 587be3e to 4218586 Compare May 9, 2026 19:55
@sukvvon sukvvon changed the title test(query-devtools/DevtoolsPanelComponent): add tests for panel-only mode and 'onClose' prop test(query-devtools/DevtoolsPanelComponent): add tests for rendering without throwing, panel-only mode, and 'onClose' prop May 9, 2026
@sukvvon sukvvon merged commit 90fbff8 into main May 9, 2026
8 checks passed
@sukvvon sukvvon deleted the test/query-devtools-devtools-panel-component branch May 9, 2026 19:57
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