Skip to content

test(vue-query/useQueries): add test for 'refetch' of individual query without affecting others#10242

Merged
TkDodo merged 2 commits intoTanStack:mainfrom
sukvvon:test/vue-query-useQueries-refetch
Mar 18, 2026
Merged

test(vue-query/useQueries): add test for 'refetch' of individual query without affecting others#10242
TkDodo merged 2 commits intoTanStack:mainfrom
sukvvon:test/vue-query-useQueries-refetch

Conversation

@sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Mar 5, 2026

🎯 Changes

Add test for per-query refetch in useQueries, verifying that refetching one query does not affect others. This covers the wrapped refetch callback in useQueries.ts lines 305-311.

✅ 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 a test verifying that triggering a refetch on one query updates only that query's data while leaving other queries unchanged.
    • Ensures independent query refetch behavior is preserved, preventing unintended cross-query updates and improving confidence in query isolation.

@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

⚠️ No Changeset found

Latest commit: d585e3e

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
Copy link
Contributor

coderabbitai bot commented Mar 5, 2026

📝 Walkthrough

Walkthrough

Adds a new unit test that verifies refetching one query in a multi-query setup updates only that query's data and does not affect other queries' data.

Changes

Cohort / File(s) Summary
Test Case Addition
packages/vue-query/src/__tests__/useQueries.test.ts
Adds test "should refetch only the specific query without affecting others" that initializes two queries, advances timers, refetches the first, and asserts only the first query's data changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through tests at break of day,

Refetched one, the rest stayed away,
One query changed, the others stayed true,
A tidy proof in green and blue,
Hooray for small checks that keep things new.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a test for per-query refetch functionality in useQueries without affecting other queries.
Description check ✅ Passed The description follows the template structure with all required sections completed: Changes section explains the test purpose, Checklist items are marked appropriately, and Release Impact correctly identifies this as dev-only with no changeset needed.
Docstring Coverage ✅ Passed No 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
📝 Coding Plan
  • Generate coding plan for human review comments

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

@nx-cloud
Copy link

nx-cloud bot commented Mar 5, 2026

View your CI Pipeline Execution ↗ for commit f423a2c

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

☁️ Nx Cloud last updated this comment at 2026-03-18 14:00:00 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 5, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: f423a2c

@sukvvon
Copy link
Contributor Author

sukvvon commented Mar 18, 2026

@TkDodo I resloved merge conflict.

Copy link
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/vue-query/src/__tests__/useQueries.test.ts (1)

380-385: Prefer async/await for side-effecting queryFns in this test.

Line 380 and Line 384 mutate counters inside .then(...); using async/await makes those side effects clearer.

♻️ Optional readability refactor
         {
           queryKey: ['users'],
-          queryFn: () => sleep(10).then(() => `users-${++userCount}`),
+          queryFn: async () => {
+            await sleep(10)
+            return `users-${++userCount}`
+          },
         },
         {
           queryKey: ['posts'],
-          queryFn: () => sleep(20).then(() => `posts-${++postCount}`),
+          queryFn: async () => {
+            await sleep(20)
+            return `posts-${++postCount}`
+          },
         },

Based on learnings: In TanStack/query test files, when a queryFn contains side effects, prefer async/await syntax for clarity.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/vue-query/src/__tests__/useQueries.test.ts` around lines 380 - 385,
The test's queryFn functions currently perform side-effecting counter increments
inside .then(...) which obscures intent; update both queryFn callbacks (the ones
using sleep and returning `users-${++userCount}` and `posts-${++postCount}`) to
be async functions that await sleep(...) and then increment the counters and
return the string (use `async`/`await` with `sleep` so the side effect
++userCount / ++postCount occurs on the next line before returning), keeping the
same queryKey names and behavior.
🤖 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/vue-query/src/__tests__/useQueries.test.ts`:
- Around line 380-385: The test's queryFn functions currently perform
side-effecting counter increments inside .then(...) which obscures intent;
update both queryFn callbacks (the ones using sleep and returning
`users-${++userCount}` and `posts-${++postCount}`) to be async functions that
await sleep(...) and then increment the counters and return the string (use
`async`/`await` with `sleep` so the side effect ++userCount / ++postCount occurs
on the next line before returning), keeping the same queryKey names and
behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2afe8af8-a816-4b80-ab19-2482daf0e7ee

📥 Commits

Reviewing files that changed from the base of the PR and between d585e3e and f423a2c.

📒 Files selected for processing (1)
  • packages/vue-query/src/__tests__/useQueries.test.ts

@TkDodo TkDodo merged commit 0249bbd into TanStack:main Mar 18, 2026
7 of 8 checks passed
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.

2 participants