test(vue-query/useQueries): add test for 'refetch' of individual query without affecting others#10242
Conversation
…y without affecting others
|
📝 WalkthroughWalkthroughAdds 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
|
View your CI Pipeline Execution ↗ for commit f423a2c
☁️ Nx Cloud last updated this comment at |
|
@TkDodo I resloved merge conflict. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/vue-query/src/__tests__/useQueries.test.ts (1)
380-385: Preferasync/awaitfor side-effectingqueryFns in this test.Line 380 and Line 384 mutate counters inside
.then(...); usingasync/awaitmakes 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
📒 Files selected for processing (1)
packages/vue-query/src/__tests__/useQueries.test.ts
🎯 Changes
Add test for per-query
refetchinuseQueries, verifying that refetching one query does not affect others. This covers the wrappedrefetchcallback inuseQueries.tslines 305-311.✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit