Skip to content

test({react,preact}-query/usePrefetchQuery): inline the 'generateQueryFn' factory into each call site#11080

Merged
sukvvon merged 2 commits into
mainfrom
test/inline-generatequeryfn-usePrefetchQuery
Jul 18, 2026
Merged

test({react,preact}-query/usePrefetchQuery): inline the 'generateQueryFn' factory into each call site#11080
sukvvon merged 2 commits into
mainfrom
test/inline-generatequeryfn-usePrefetchQuery

Conversation

@sukvvon

@sukvvon sukvvon commented Jul 18, 2026

Copy link
Copy Markdown
Member

🎯 Changes

Inlines the generateQueryFn factory (used 9 times) directly at each call site as vi.fn(() => sleep(10).then(() => '...')), matching the plain inline queryFn style used elsewhere in the test suite. vi.fn() is retained (not a bare arrow function) because several assertions depend on it being a spy: toHaveBeenCalledTimes, .mockClear(), and .mockImplementationOnce() to simulate a failed fetch. The explicit generic type parameter on the removed factory wasn't load-bearing — vi.fn(impl) infers the same signature from its implementation. Applies to both react-query and preact-query.

✅ 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
    • Improved usePrefetchQuery tests with scenario-specific mocked queryFn implementations instead of a shared helper.
    • Verified prefetch behavior when cached state is missing versus already present.
    • Strengthened coverage for error handling, retry recovery, suspense boundary edge cases, and prevention of suspense waterfalls.
    • Confirmed sequential prefetch operations behave correctly and that failed queries aren’t unnecessarily re-fetched.

@nx-cloud

nx-cloud Bot commented Jul 18, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit fdd34ca

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

☁️ Nx Cloud last updated this comment at 2026-07-18 17:27:30 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.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 565c6488-f43d-42bf-b0b8-4b4d4a951dab

📥 Commits

Reviewing files that changed from the base of the PR and between fdcf331 and fdd34ca.

📒 Files selected for processing (2)
  • packages/preact-query/src/__tests__/usePrefetchQuery.test.tsx
  • packages/react-query/src/__tests__/usePrefetchQuery.test.tsx

📝 Walkthrough

Walkthrough

The React and Preact usePrefetchQuery tests remove the shared generateQueryFn helper and define equivalent asynchronous vi.fn query functions within each affected test.

Changes

usePrefetchQuery test mock refactor

Layer / File(s) Summary
Inline per-test query functions
packages/react-query/src/__tests__/usePrefetchQuery.test.tsx, packages/preact-query/src/__tests__/usePrefetchQuery.test.tsx
Replaces generateQueryFn with explicit vi.fn implementations across prefetch, error, suspense, recovery, and waterfall scenarios while preserving delays and returned values.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • TanStack/query#11056: Refactors usePrefetchQuery test query function setup and related option assertions.
  • TanStack/query#11075: Updates the same usePrefetchQuery test suite with an immediate Suspense fallback assertion.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the test refactor of inlining generateQueryFn across react/preact-query.
Description check ✅ Passed The description follows the template and includes changes, checklist, and release impact details.
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.
✨ 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/inline-generatequeryfn-usePrefetchQuery

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

@pkg-pr-new

pkg-pr-new Bot commented Jul 18, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: fdd34ca

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

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

@sukvvon
sukvvon marked this pull request as draft July 18, 2026 17:14
@sukvvon sukvvon self-assigned this Jul 18, 2026
….fn()' wrapper on the never-asserted sentinel queryFn
@sukvvon
sukvvon marked this pull request as ready for review July 18, 2026 17:36
@sukvvon
sukvvon merged commit d1558c1 into main Jul 18, 2026
8 of 9 checks passed
@sukvvon
sukvvon deleted the test/inline-generatequeryfn-usePrefetchQuery branch July 18, 2026 17:36
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