Conversation
…in test 'queryFn' and 'mutationFn'
📝 WalkthroughWalkthroughThis PR refactors test code across five test files in the react-query package, converting query and mutation function implementations from async/await syntax to promise-chained Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
View your CI Pipeline Execution ↗ for commit e5dc162
☁️ Nx Cloud last updated this comment at |
🚀 Changeset Version PreviewNo changeset entries found. Merging this PR will not cause a version bump for any packages. |
More templates
@tanstack/angular-query-experimental
@tanstack/eslint-plugin-query
@tanstack/preact-query
@tanstack/preact-query-devtools
@tanstack/preact-query-persist-client
@tanstack/query-async-storage-persister
@tanstack/query-broadcast-client-experimental
@tanstack/query-core
@tanstack/query-devtools
@tanstack/query-persist-client-core
@tanstack/query-sync-storage-persister
@tanstack/react-query
@tanstack/react-query-devtools
@tanstack/react-query-next-experimental
@tanstack/react-query-persist-client
@tanstack/solid-query
@tanstack/solid-query-devtools
@tanstack/solid-query-persist-client
@tanstack/svelte-query
@tanstack/svelte-query-devtools
@tanstack/svelte-query-persist-client
@tanstack/vue-query
@tanstack/vue-query-devtools
commit: |
size-limit report 📦
|
There was a problem hiding this comment.
🧹 Nitpick comments (3)
packages/react-query/src/__tests__/useQueries.test.tsx (1)
1090-1094: Simplify redundantPromise.resolve()wrapping in.then()chains.
.then(() => Promise.resolve('x'))can be simplified to.then(() => 'x')— the Promise chain automatically wraps the return value. Found at lines 1090, 1094, 1130, and 1135.Suggested simplification
- queryFn: () => sleep(5).then(() => Promise.resolve('query1')), + queryFn: () => sleep(5).then(() => 'query1'), - queryFn: () => sleep(20).then(() => Promise.resolve('query2')), + queryFn: () => sleep(20).then(() => 'query2'), - queryFn: () => - sleep(5).then(() => Promise.resolve('first result ' + count)), + queryFn: () => sleep(5).then(() => 'first result ' + count), - queryFn: () => - sleep(50).then(() => Promise.resolve('second result ' + count)), + queryFn: () => sleep(50).then(() => 'second result ' + count),🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/react-query/src/__tests__/useQueries.test.tsx` around lines 1090 - 1094, The test query functions (queryFn in the useQueries tests) unnecessarily wrap return values in Promise.resolve within .then chains; update the queryFn implementations (e.g., the functions defined for queryKey key1/key2 and the other instances at lines shown in the diff) to return the plain value from the .then callbacks (replace .then(() => Promise.resolve('x')) with .then(() => 'x')) so the promise chain still resolves correctly but with simpler, cleaner code.packages/react-query/src/__tests__/useQuery.test.tsx (1)
4890-4892: Simplify Promise.resolve/reject wrappers inside.then()callbacks to improve clarity.These Promise wrappers are unnecessary; use direct
throwfor errors and direct return values for success cases.Instances to refactor (6 total)
- Line 4891:
Promise.reject(new Error(...))→throw new Error(...)- Line 5013:
Promise.reject<unknown>(new Error(...))→throw new Error(...)- Line 6418:
Promise.resolve('data')→'data'- Line 6495:
Promise.reject(error)→throw error- Line 6594:
Promise.resolve('server')→'server'- Line 6650:
Promise.reject(new Error(...))→throw new Error(...)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/react-query/src/__tests__/useQuery.test.tsx` around lines 4890 - 4892, In the test file useQuery.test.tsx, simplify the unnecessary Promise.resolve/Promise.reject inside .then() callbacks by replacing Promise.reject(new Error(...)) or Promise.reject(error) with throwing the error (e.g., throw new Error(...) or throw error), and replacing Promise.resolve('value') with returning the plain value ('value'); specifically update the queryFn.mockImplementation(...) callbacks and the other .then(...) handlers referenced (instances around the mockImplementation at queryFn.mockImplementation and the other six occurrences) so the .then() bodies directly throw or return values instead of wrapping them in Promise.resolve/Promise.reject.packages/react-query/src/__tests__/useMutation.test.tsx (1)
160-162: RedundantPromise.resolvewrapper inside.then()callback.Returning a value from a
.then()callback automatically wraps it in a resolved promise. The explicitPromise.resolve(value)is unnecessary and inconsistent with the other refactored lines (371, 1032) that use.then(() => value)directly.Suggested simplification
- mutateFn.mockImplementation((value) => - sleep(10).then(() => Promise.resolve(value)), - ) + mutateFn.mockImplementation((value) => sleep(10).then(() => value))🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/react-query/src/__tests__/useMutation.test.tsx` around lines 160 - 162, The mock implementation for mutateFn is wrapping the returned value in Promise.resolve unnecessarily; update the mutateFn.mockImplementation callback to return the value directly (e.g., replace the `.then(() => Promise.resolve(value))` with `.then(() => value)`) so it matches other refactored lines and avoids redundant Promise wrapping in the mock.
🤖 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/react-query/src/__tests__/useMutation.test.tsx`:
- Around line 160-162: The mock implementation for mutateFn is wrapping the
returned value in Promise.resolve unnecessarily; update the
mutateFn.mockImplementation callback to return the value directly (e.g., replace
the `.then(() => Promise.resolve(value))` with `.then(() => value)`) so it
matches other refactored lines and avoids redundant Promise wrapping in the
mock.
In `@packages/react-query/src/__tests__/useQueries.test.tsx`:
- Around line 1090-1094: The test query functions (queryFn in the useQueries
tests) unnecessarily wrap return values in Promise.resolve within .then chains;
update the queryFn implementations (e.g., the functions defined for queryKey
key1/key2 and the other instances at lines shown in the diff) to return the
plain value from the .then callbacks (replace .then(() => Promise.resolve('x'))
with .then(() => 'x')) so the promise chain still resolves correctly but with
simpler, cleaner code.
In `@packages/react-query/src/__tests__/useQuery.test.tsx`:
- Around line 4890-4892: In the test file useQuery.test.tsx, simplify the
unnecessary Promise.resolve/Promise.reject inside .then() callbacks by replacing
Promise.reject(new Error(...)) or Promise.reject(error) with throwing the error
(e.g., throw new Error(...) or throw error), and replacing
Promise.resolve('value') with returning the plain value ('value'); specifically
update the queryFn.mockImplementation(...) callbacks and the other .then(...)
handlers referenced (instances around the mockImplementation at
queryFn.mockImplementation and the other six occurrences) so the .then() bodies
directly throw or return values instead of wrapping them in
Promise.resolve/Promise.reject.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 85f44e05-d58a-4848-8f13-a12d4f2b15e1
📒 Files selected for processing (5)
packages/react-query/src/__tests__/fine-grained-persister.test.tsxpackages/react-query/src/__tests__/useMutation.test.tsxpackages/react-query/src/__tests__/usePrefetchQuery.test.tsxpackages/react-query/src/__tests__/useQueries.test.tsxpackages/react-query/src/__tests__/useQuery.test.tsx
🎯 Changes
async () => { await sleep(N); return value }with() => sleep(N).then(() => value)in testqueryFnandmutationFnuseQuery.test.tsx,useQueries.test.tsx,useMutation.test.tsx,usePrefetchQuery.test.tsx, andfine-grained-persister.test.tsx✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit
Release Notes