Skip to content

test(angular-query-experimental/withDevtools): add test for 'No QueryClient found' throw when 'loadDevtools' is 'true' without a 'QueryClient'#10544

Merged
sukvvon merged 1 commit intomainfrom
test/angular-query-with-devtools-no-query-client
Apr 21, 2026
Merged

test(angular-query-experimental/withDevtools): add test for 'No QueryClient found' throw when 'loadDevtools' is 'true' without a 'QueryClient'#10544
sukvvon merged 1 commit intomainfrom
test/angular-query-with-devtools-no-query-client

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Apr 21, 2026

🎯 Changes

Adds a test covering the throw new Error('No QueryClient found') branch in with-devtools.ts (line 109). When loadDevtools: true is set but no QueryClient is provided (e.g. provideTanStackQuery is missing), the dynamic devtools loader now has explicit coverage that the error is thrown and handled by the .catch branch.

What's tested

  • withDevtools(() => ({ loadDevtools: true })).ɵproviders is registered without provideTanStackQuery(queryClient).
  • Triggering ENVIRONMENT_INITIALIZER + one change detection cycle starts the dynamic import('@tanstack/query-devtools').
  • Inside the .then, getResolvedQueryClient() throws because neither devtoolsOptions().client nor the optionally injected QueryClient is present.
  • The .catch branch catches the thrown error and logs it via console.error.

Line 169 (console.error in the .catch) is covered as a natural consequence of the thrown error being propagated through the Promise chain.

✅ 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 validation to ensure proper error messaging when devtools is configured without a required client.

…Client found' throw when 'loadDevtools' is 'true' without a 'QueryClient'
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 21, 2026

📝 Walkthrough

Walkthrough

A new test case was added to verify that when withDevtools is configured to load devtools without providing a QueryClient, the devtools dynamic import does not execute and appropriate error messages are logged to the console.

Changes

Cohort / File(s) Summary
Devtools Error Handling Test
packages/angular-query-experimental/src/__tests__/with-devtools.test.ts
Added test case verifying devtools dynamic import is skipped when no QueryClient is provided, with assertions on console.error output and message content.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A test was born beneath the moon so bright,
To catch the devtools dancing in the night,
"No QueryClient?" it cried with glee,
Error messages flow, as they should be! 🎯

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the new test added, matching the main change in the changeset.
Description check ✅ Passed The description follows the required template with all sections completed: Changes section explains the test coverage, Checklist items are marked, and Release Impact is properly addressed.
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/angular-query-with-devtools-no-query-client

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

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 21, 2026

View your CI Pipeline Execution ↗ for commit 6653ce5

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

☁️ Nx Cloud last updated this comment at 2026-04-21 15:17:51 UTC

@github-actions
Copy link
Copy Markdown
Contributor

🚀 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 Apr 21, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 6653ce5

@github-actions
Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
react full 11.99 KB (0%)
react minimal 9.02 KB (0%)

@sukvvon sukvvon self-assigned this Apr 21, 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/angular-query-experimental/src/__tests__/with-devtools.test.ts (1)

170-178: Align async flushing with the suite’s fake-timer pattern to reduce flakiness.

Since fake timers are enabled globally, this test is more deterministic if it advances timers before settling dynamic imports (like other tests in this file). Also consider asserting console.error call count.

Suggested tweak
     TestBed.inject(ENVIRONMENT_INITIALIZER)
-    TestBed.tick()
+    await vi.advanceTimersByTimeAsync(0)
+    TestBed.tick()
     await vi.dynamicImportSettled()
+    TestBed.tick()
+    await vi.dynamicImportSettled()

     expect(mockTanstackQueryDevtools).not.toHaveBeenCalled()
+    expect(consoleErrorSpy).toHaveBeenCalledTimes(1)
     expect(consoleErrorSpy).toHaveBeenCalledWith(
       'Install `@tanstack/query-devtools` or reinstall without --omit=optional.',
       expect.objectContaining({ message: 'No QueryClient found' }),
     )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/angular-query-experimental/src/__tests__/with-devtools.test.ts`
around lines 170 - 178, Advance the fake timers with TestBed.tick() (or
equivalent) before awaiting vi.dynamicImportSettled() in the test that calls
TestBed.inject(ENVIRONMENT_INITIALIZER) so dynamic imports are flushed under the
suite's fake-timer pattern; then await vi.dynamicImportSettled(), and add an
assertion on consoleErrorSpy call count (e.g., toHaveBeenCalledTimes(1))
alongside the existing expect statements for mockTanstackQueryDevtools and the
console error message to reduce flakiness and make the expectation explicit.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/angular-query-experimental/src/__tests__/with-devtools.test.ts`:
- Around line 170-178: Advance the fake timers with TestBed.tick() (or
equivalent) before awaiting vi.dynamicImportSettled() in the test that calls
TestBed.inject(ENVIRONMENT_INITIALIZER) so dynamic imports are flushed under the
suite's fake-timer pattern; then await vi.dynamicImportSettled(), and add an
assertion on consoleErrorSpy call count (e.g., toHaveBeenCalledTimes(1))
alongside the existing expect statements for mockTanstackQueryDevtools and the
console error message to reduce flakiness and make the expectation explicit.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 888d4093-e12a-4839-8515-063711043305

📥 Commits

Reviewing files that changed from the base of the PR and between 50d08de and 6653ce5.

📒 Files selected for processing (1)
  • packages/angular-query-experimental/src/__tests__/with-devtools.test.ts

@sukvvon sukvvon merged commit ad3bc84 into main Apr 21, 2026
10 checks passed
@sukvvon sukvvon deleted the test/angular-query-with-devtools-no-query-client branch April 21, 2026 15:18
Ephem pushed a commit to Ephem/react-query that referenced this pull request Apr 23, 2026
…Client found' throw when 'loadDevtools' is 'true' without a 'QueryClient' (TanStack#10544)
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