Skip to content

test(query-devtools/TanstackQueryDevtools): replace placeholder with 'mount' and 'unmount' lifecycle tests#10639

Merged
sukvvon merged 1 commit into
mainfrom
test/query-devtools-lifecycle
May 5, 2026
Merged

test(query-devtools/TanstackQueryDevtools): replace placeholder with 'mount' and 'unmount' lifecycle tests#10639
sukvvon merged 1 commit into
mainfrom
test/query-devtools-lifecycle

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented May 5, 2026

🎯 Changes

Replace the placeholder test (expect(1).toBe(1)) with the first real lifecycle tests for the TanstackQueryDevtools core class.

  • Remove src/__tests__/devtools.test.tsx (placeholder)
  • Add src/__tests__/TanstackQueryDevtools.test.tsx with 5 cases covering mount/unmount lifecycle and guard behavior:
    • mount: succeeds on a provided element / throws on double mount
    • unmount: allows remounting / throws when called before mount / throws on double unmount

Setter contract and reactive UI behavior are intentionally out of scope for this PR — they will be covered in follow-up PRs.

✅ 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 Vitest tests covering devtools initialization, mount/unmount flows and error-handling for repeated or invalid mount/unmount sequences.
    • Removed a placeholder test suite.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 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: 0ca9748d-bc9f-4550-b766-cd0b7c4f1c07

📥 Commits

Reviewing files that changed from the base of the PR and between d7bf361 and 03095cb.

📒 Files selected for processing (2)
  • packages/query-devtools/src/__tests__/TanstackQueryDevtools.test.tsx
  • packages/query-devtools/src/__tests__/devtools.test.tsx
💤 Files with no reviewable changes (1)
  • packages/query-devtools/src/tests/devtools.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/query-devtools/src/tests/TanstackQueryDevtools.test.tsx

📝 Walkthrough

Walkthrough

Adds a new Vitest test suite for TanstackQueryDevtools that exercises initialization, mount/unmount lifecycle, and error cases; removes a placeholder ReactQueryDevtools test file.

Changes

Test Suite Replacement

Layer / File(s) Summary
Test Setup
packages/query-devtools/src/__tests__/TanstackQueryDevtools.test.tsx
beforeEach creates a new TanstackQueryDevtools with a fresh QueryClient, queryFlavor: 'TanStack Query', version: '5', and onlineManager.
Mount Behavior
packages/query-devtools/src/__tests__/TanstackQueryDevtools.test.tsx
Adds tests asserting mount(el) does not throw and that calling mount twice without unmount throws 'Devtools is already mounted'.
Unmount Behavior
packages/query-devtools/src/__tests__/TanstackQueryDevtools.test.tsx
Adds tests asserting unmount() works after mount, allows remount after unmount, throws 'Devtools is not mounted' when called before mounting, and throws same error if called twice after a single mount.
Test Removal
packages/query-devtools/src/__tests__/devtools.test.tsx
Removes placeholder Vitest test that asserted devtools could open/close with a trivial expect(1).toBe(1).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 New tests hop in, precise and spry,
Mounts and unmounts traced beneath the sky,
Old placeholders gone, assertions take flight,
Devtools now checked from morning to night.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: replacing a placeholder test with concrete mount/unmount lifecycle tests for TanstackQueryDevtools.
Description check ✅ Passed The PR description covers all required template sections with specific details about changes, completed checklist items, and release impact classification.
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-devtools-lifecycle

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

@sukvvon sukvvon self-assigned this May 5, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 5, 2026

View your CI Pipeline Execution ↗ for commit 03095cb

Command Status Duration Result
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-05 12:27:00 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 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.

🧹 Nitpick comments (1)
packages/query-devtools/src/__tests__/TanstackQueryDevtools.test.tsx (1)

8-15: ⚡ Quick win

Consider adding an afterEach hook for cleanup.

While each test gets a fresh devtools instance, adding cleanup in afterEach would make the suite more robust—especially if a test fails partway through and leaves resources mounted. Additionally, TanStack Query best practice recommends clearing the QueryClient after tests.

🧹 Proposed cleanup hook
   })
+
+  afterEach(() => {
+    // Safe cleanup even if test fails partway
+    try {
+      devtools.unmount()
+    } catch {
+      // Already unmounted or never mounted
+    }
+  })
 
   describe('mount', () => {
🤖 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__/TanstackQueryDevtools.test.tsx` around
lines 8 - 15, Create a shared QueryClient variable and add an afterEach cleanup
that clears the client and unmounts/disposes the devtools: move new
QueryClient() out of the TanstackQueryDevtools constructor into a top-level
queryClient variable used in beforeEach, then add afterEach which calls await
queryClient.clear(); if (devtools?.unmount) call devtools.unmount(); else if
(devtools?.dispose) call devtools.dispose(); finally set devtools = undefined to
ensure no mounted resources remain (referencing queryClient and
devtools/TanstackQueryDevtools).
🤖 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__/TanstackQueryDevtools.test.tsx`:
- Around line 8-15: Create a shared QueryClient variable and add an afterEach
cleanup that clears the client and unmounts/disposes the devtools: move new
QueryClient() out of the TanstackQueryDevtools constructor into a top-level
queryClient variable used in beforeEach, then add afterEach which calls await
queryClient.clear(); if (devtools?.unmount) call devtools.unmount(); else if
(devtools?.dispose) call devtools.dispose(); finally set devtools = undefined to
ensure no mounted resources remain (referencing queryClient and
devtools/TanstackQueryDevtools).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 06108795-ed78-4107-8428-49ff7a7f2dd5

📥 Commits

Reviewing files that changed from the base of the PR and between 0d63459 and d7bf361.

📒 Files selected for processing (2)
  • packages/query-devtools/src/__tests__/TanstackQueryDevtools.test.tsx
  • packages/query-devtools/src/__tests__/devtools.test.tsx
💤 Files with no reviewable changes (1)
  • packages/query-devtools/src/tests/devtools.test.tsx

@sukvvon sukvvon force-pushed the test/query-devtools-lifecycle branch from d7bf361 to 03095cb Compare May 5, 2026 11:49
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 5, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 03095cb

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

size-limit report 📦

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

@sukvvon sukvvon merged commit 5892279 into main May 5, 2026
11 of 12 checks passed
@sukvvon sukvvon deleted the test/query-devtools-lifecycle branch May 5, 2026 12:36
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