Skip to content

test(preact-query): replace 'async/await sleep' with 'sleep().then()' in test 'queryFn' and 'mutationFn' - #10400

Merged
sukvvon merged 2 commits into
mainfrom
test/preact-query-replace-async-await-sleep-with-then-chaining
Apr 6, 2026
Merged

test(preact-query): replace 'async/await sleep' with 'sleep().then()' in test 'queryFn' and 'mutationFn'#10400
sukvvon merged 2 commits into
mainfrom
test/preact-query-replace-async-await-sleep-with-then-chaining

Conversation

@sukvvon

@sukvvonsukvvon commented Apr 6, 2026

Copy link
Copy Markdown
Member

🎯 Changes

  • Replace async () => { await sleep(N); return value } with () => sleep(N).then(() => value) in test queryFn and mutationFn
  • Applied to useQuery.test.tsx, useQueries.test.tsx, useMutation.test.tsx, usePrefetchQuery.test.tsx, useSuspenseQueries.test.tsx, and fine-grained-persister.test.tsx

✅ 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
    • Refactored test implementations to use promise chaining patterns. No user-facing changes.

@coderabbitai

coderabbitaiBot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR converts test implementations across multiple test files from async/await syntax to promise chaining with .then(). All changes are test-only, affecting queryFn and mutationFn mock implementations while preserving timing and resolved values.

Changes

Cohort / File(s)Summary
Query Test Function Refactors
packages/preact-query/src/__tests__/useQuery.test.tsx, packages/preact-query/src/__tests__/useQueries.test.tsx, packages/preact-query/src/__tests__/usePrefetchQuery.test.tsx, packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx
Converted multiple queryFn implementations from async () => { await sleep(...); return X } to () => sleep(...).then(() => X), preserving promise timing and resolved values across all query-related test cases.
Mutation Test Function Refactors
packages/preact-query/src/__tests__/useMutation.test.tsx
Converted mutationFn implementations from async (text) => { await sleep(...); return text } to (text) => sleep(...).then(() => text) patterns, maintaining async behavior through direct promise chaining.
Mock Spy Refactors
packages/preact-query/src/__tests__/fine-grained-persister.test.tsx
Changed test spy mock from async function with await sleep(5) to direct promise chain sleep(5).then(() => 'Works from queryFn').

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 Async hops have found a chain,
Where .then() flows without the await refrain,
Same timing, same promise delight,
Just syntax tweaks—the logic's still right! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check nameStatusExplanation
Title check✅ PassedThe title accurately describes the main change: replacing async/await sleep patterns with promise chaining in test queryFn and mutationFn implementations across multiple test files.
Description check✅ PassedThe description follows the template structure with completed 🎯 Changes and 🚀 Release Impact sections, clearly documenting what was changed and marking it as dev-only with appropriate checklist items.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/preact-query-replace-async-await-sleep-with-then-chaining

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

@sukvvonsukvvon self-assigned this Apr 6, 2026
@nx-cloud

nx-cloudBot commented Apr 6, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit d2d2362

CommandStatusDurationResult
nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded1m 50sView ↗
nx run-many --target=build --exclude=examples/*...✅ Succeeded<1sView ↗

☁️ Nx Cloud last updated this comment at 2026-04-06 05:46:17 UTC

@github-actions

github-actionsBot commented Apr 6, 2026

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-newBot commented Apr 6, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: d2d2362

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
react full11.98 KB (0%)
react minimal9.01 KB (0%)

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/preact-query/src/__tests__/useMutation.test.tsx (1)

161-163: Redundant Promise.resolve inside .then() callback.

The .then() callback automatically wraps the returned value in a Promise, making Promise.resolve(value) unnecessary. This should just return value directly for consistency with the other changes in this PR.

Suggested fix
- 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/preact-query/src/__tests__/useMutation.test.tsx` around lines 161 -
163, The mock implementation for mutateFn uses Promise.resolve inside a .then
callback which is redundant; update mutateFn.mockImplementation((value) =>
sleep(10).then(() => Promise.resolve(value))) to simply return the value from
the .then callback (i.e., .then(() => value)) so the promise resolves the same
way and matches the style of other tests; locate and change the
mutateFn.mockImplementation call in useMutation.test.tsx.
🤖 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/preact-query/src/__tests__/useMutation.test.tsx`:
- Around line 161-163: The mock implementation for mutateFn uses Promise.resolve
inside a .then callback which is redundant; update
mutateFn.mockImplementation((value) => sleep(10).then(() =>
Promise.resolve(value))) to simply return the value from the .then callback
(i.e., .then(() => value)) so the promise resolves the same way and matches the
style of other tests; locate and change the mutateFn.mockImplementation call in
useMutation.test.tsx.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2f567c03-2339-478d-8002-dc10b8ce68b1

📥 Commits

Reviewing files that changed from the base of the PR and between 7d7a21c and d2d2362.

📒 Files selected for processing (6)
  • packages/preact-query/src/__tests__/fine-grained-persister.test.tsx
  • packages/preact-query/src/__tests__/useMutation.test.tsx
  • packages/preact-query/src/__tests__/usePrefetchQuery.test.tsx
  • packages/preact-query/src/__tests__/useQueries.test.tsx
  • packages/preact-query/src/__tests__/useQuery.test.tsx
  • packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx

@sukvvon
sukvvon merged commit eac62b8 into mainApr 6, 2026
8 checks passed
@sukvvon
sukvvon deleted the test/preact-query-replace-async-await-sleep-with-then-chaining branch April 6, 2026 06:25
Sign up for freeto 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.

1 participant

@sukvvon