Skip to content

test(query-core/queryObserver): add test for rejecting promise when 'experimental_prefetchInRender' is disabled - #10249

Merged
TkDodo merged 1 commit into
TanStack:mainfrom
sukvvon:test/query-core-queryObserver-reject-promise-without-prefetchInRender
Mar 11, 2026
Merged

test(query-core/queryObserver): add test for rejecting promise when 'experimental_prefetchInRender' is disabled#10249
TkDodo merged 1 commit into
TanStack:mainfrom
sukvvon:test/query-core-queryObserver-reject-promise-without-prefetchInRender

Conversation

@sukvvon

@sukvvonsukvvon commented Mar 6, 2026

Copy link
Copy Markdown
Member

🎯 Changes

Add a test for queryObserver.ts lines 272-277 — trackResult rejecting the pending thenable when experimental_prefetchInRender is disabled and .promise is accessed.

✅ 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 coverage verifying that when the experimental prefetch feature is disabled, in-flight thenables are rejected with a clear, specific error message.

@changeset-bot

changeset-botBot commented Mar 6, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: df8f53a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitaiBot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fd78d545-004e-4c58-818b-fe8c522abec1

📥 Commits

Reviewing files that changed from the base of the PR and between bcbaa6d and df8f53a.

📒 Files selected for processing (1)
  • packages/query-core/src/__tests__/queryObserver.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/query-core/src/tests/queryObserver.test.tsx

📝 Walkthrough

Walkthrough

Adds two identical tests to QueryObserver's test suite asserting that when experimental_prefetchInRender is disabled and the query function returns a pending thenable, the observer's tracked promise rejects with "experimental_prefetchInRender feature flag is not enabled".

Changes

Cohort / File(s)Summary
QueryObserver tests
packages/query-core/src/__tests__/queryObserver.test.tsx
Adds two identical test cases that construct a QueryClient with experimental_prefetchInRender disabled, create a QueryObserver whose queryFn returns a pending thenable, call getCurrentResult()/trackResult() and assert the tracked result.promise rejects with the feature-flag error message.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I nibbled at flags in the test-tree light,
A thenable hung, refusing to take flight,
Two gentle checks to catch the silent plea,
"Feature off," it sighed — the promise set me free,
🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check nameStatusExplanation
Title check✅ PassedThe title clearly and concisely describes the main change: adding a test for promise rejection when the experimental_prefetchInRender feature flag is disabled.
Description check✅ PassedThe description follows the repository template with all required sections completed: Changes are clearly described, checklist items are marked as completed, and release impact is properly documented as dev-only.
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@nx-cloud

nx-cloudBot commented Mar 6, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit df8f53a

CommandStatusDurationResult
nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded3m 43sView ↗
nx run-many --target=build --exclude=examples/*...✅ Succeeded1sView ↗

☁️ Nx Cloud last updated this comment at 2026-03-06 04:57:12 UTC

@pkg-pr-new

pkg-pr-newBot commented Mar 6, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 5e1bc1f

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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-core/src/__tests__/queryObserver.test.tsx (1)

1399-1403: Assert on tracked.promise directly to make the test precise

This keeps the assertion aligned with the behavior under test (trackResult) and avoids the extra void access pattern.

Proposed diff
- void tracked.promise-- await expect(result.promise).rejects.toThrow(+ await expect(tracked.promise).rejects.toThrow(
'experimental_prefetchInRender feature flag is not enabled',
)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/query-core/src/__tests__/queryObserver.test.tsx` around lines 1399 -
1403, The test currently uses a redundant `void tracked.promise` and then
asserts `result.promise`; update it to assert `tracked.promise` directly to
accurately test the behavior of `trackResult` — remove the `void
tracked.promise` line and change the expectation from
`expect(result.promise).rejects.toThrow(...)` to
`expect(tracked.promise).rejects.toThrow(...)`, keeping the same error message
assertion.
🤖 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/query-core/src/__tests__/queryObserver.test.tsx`:
- Around line 1399-1403: The test currently uses a redundant `void
tracked.promise` and then asserts `result.promise`; update it to assert
`tracked.promise` directly to accurately test the behavior of `trackResult` —
remove the `void tracked.promise` line and change the expectation from
`expect(result.promise).rejects.toThrow(...)` to
`expect(tracked.promise).rejects.toThrow(...)`, keeping the same error message
assertion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dbcc6ceb-e941-4f52-9dd3-c9788ca19816

📥 Commits

Reviewing files that changed from the base of the PR and between fe25edc and 6bc99ca.

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

@sukvvon
sukvvonforce-pushed the test/query-core-queryObserver-reject-promise-without-prefetchInRender branch from 6bc99ca to bcbaa6dCompareMarch 6, 2026 04:47

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

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 the current code and only fix it if needed.
Inline comments:
In `@packages/query-core/src/__tests__/queryObserver.test.tsx`:
- Around line 1381-1402: The test creates a local QueryClient instance
(queryClient2) but never clears it; add cleanup by calling await
queryClient2.clear() (or queryClient2.clear() in a finally block) at the end of
the test so the QueryClient is torn down after the assertions; locate the test
that instantiates QueryClient(queryClient2) and insert the clear call (using the
same queryClient2 identifier) so resources are released.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 72235061-8450-47e4-9bb4-bba61e9bae7e

📥 Commits

Reviewing files that changed from the base of the PR and between 6bc99ca and bcbaa6d.

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

Comment threadpackages/query-core/src/__tests__/queryObserver.test.tsx
@sukvvon
sukvvonforce-pushed the test/query-core-queryObserver-reject-promise-without-prefetchInRender branch from bcbaa6d to df8f53aCompareMarch 6, 2026 04:52
@TkDodo
TkDodo merged commit db663de into TanStack:mainMar 11, 2026
6 checks passed
@sukvvonsukvvon self-assigned this Mar 19, 2026
Sign up for freeto 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.

2 participants

@sukvvon@TkDodo