Skip to content

test(vue-query/{usePrefetchQuery,usePrefetchInfiniteQuery}): assert exact prefetch options instead of 'objectContaining'#11056

Merged
sukvvon merged 1 commit into
mainfrom
test/vue-query-prefetch-assert-exact-options
Jul 12, 2026
Merged

test(vue-query/{usePrefetchQuery,usePrefetchInfiniteQuery}): assert exact prefetch options instead of 'objectContaining'#11056
sukvvon merged 1 commit into
mainfrom
test/vue-query-prefetch-assert-exact-options

Conversation

@sukvvon

@sukvvon sukvvon commented Jul 12, 2026

Copy link
Copy Markdown
Member

🎯 Changes

The usePrefetchQuery / usePrefetchInfiniteQuery tests spy on queryClient.prefetchQuery / prefetchInfiniteQuery and check the forwarded options. They matched only queryKey via expect.objectContaining(...), leaving the rest of the forwarded options (queryFn, initialPageParam, getNextPageParam) unverified. Since cloneDeepUnref preserves function references, the full options object can be asserted exactly.

  • objectContaining({ queryKey }) → exact object — asserts the whole forwarded options, so extra/missing keys are caught.
  • expect.any(Function) → reference — inline queryFn / getNextPageParam are extracted to consts and asserted by reference, so the test verifies the exact function is forwarded, not just "some function". A sibling test already used this reference-matching style.
  • toHaveBeenLastCalledWithtoHaveBeenNthCalledWith(n, ...) in the reactive-key-change tests, pinning each call to its position (first call = old key, second = new key). The redundant toHaveBeenCalledTimes(1) before the first Nth(1) is dropped, while the toHaveBeenCalledTimes(2) guarding the total call count is kept.
  • queryFn unwrapped from vi.fn(...) to a plain function — these tests never use its mock features, so the wrapper was noise; getNextPageParam was already plain.

✅ Checklist

🚀 Release Impact

  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Tests
    • Strengthened coverage for query and infinite-query prefetching.
    • Improved precision in assertions for prefetch call options, including exact query function references and unwrapped reactive query-key values.
    • Updated expectations to verify correct behavior across initial and reactive query-key changes (including “do not prefetch when state exists” scenarios).
    • No user-facing behavior changes.

@sukvvon sukvvon self-assigned this Jul 12, 2026
@nx-cloud

nx-cloud Bot commented Jul 12, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit c08c5fa

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

☁️ Nx Cloud last updated this comment at 2026-07-12 16:53:39 UTC

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Vue prefetch query and infinite-query tests now use stable query functions and assert exact prefetch options, including unwrapped reactive keys, pagination callbacks, and ordered calls after reactive key changes.

Changes

Vue prefetch test assertions

Layer / File(s) Summary
Exact prefetch option assertions
packages/vue-query/src/__tests__/usePrefetchQuery.test.ts, packages/vue-query/src/__tests__/usePrefetchInfiniteQuery.test.ts
Tests use direct or shared function references and verify complete prefetch option objects, unwrapped keys, pagination callbacks, and first/second reactive invocations.

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

Possibly related PRs

  • TanStack/query#11051: Tightens reactive prefetch/refetch assertions for exact second-call arguments in related framework tests.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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 clearly summarizes the main test-only change: asserting exact forwarded prefetch options instead of partial matching.
Description check ✅ Passed The description matches the template and includes the changes, checklist, and release impact sections with sufficient detail.
✨ 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/vue-query-prefetch-assert-exact-options

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

@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

pkg-pr-new Bot commented Jul 12, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: dd5a785

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

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

…xact prefetch options instead of 'objectContaining'
@sukvvon sukvvon force-pushed the test/vue-query-prefetch-assert-exact-options branch from c08c5fa to dd5a785 Compare July 12, 2026 16:46
@sukvvon sukvvon changed the title test(vue-query/usePrefetch): assert exact prefetch options instead of 'objectContaining' test(vue-query/{usePrefetchQuery,usePrefetchInfiniteQuery}): assert exact prefetch options instead of 'objectContaining' Jul 12, 2026
@sukvvon sukvvon merged commit fb8f474 into main Jul 12, 2026
11 of 12 checks passed
@sukvvon sukvvon deleted the test/vue-query-prefetch-assert-exact-options branch July 12, 2026 16:56
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