Skip to content

test({react,preact}-query/useMutation): add conditional handling and retry tests using 'mutate' callbacks#10491

Merged
sukvvon merged 2 commits intomainfrom
test/react-preact-query-useMutation-conditional-and-retry
Apr 13, 2026
Merged

test({react,preact}-query/useMutation): add conditional handling and retry tests using 'mutate' callbacks#10491
sukvvon merged 2 commits intomainfrom
test/react-preact-query-useMutation-conditional-and-retry

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Apr 13, 2026

🎯 Changes

  • Add 2 runtime tests for useMutation real-world scenarios using mutate callbacks in both react-query and preact-query:
    • should handle conditional logic based on mutate success or failure: uses mutate with onSuccess/onError callbacks to show success or error message based on mutation result
    • should handle conditional error with retry using mutate: first attempt fails with onError callback, user clicks again to retry and succeeds with onSuccess callback
  • Uses mutate + callback pattern (TanStack Query recommended) instead of mutateAsync + try/catch

✅ 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 test coverage for useMutation error and success handling with variable inputs and retry scenarios across Preact Query and React Query.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dd656875-8c37-490d-b955-fc5061b2d6a2

📥 Commits

Reviewing files that changed from the base of the PR and between 6e15fe6 and 9a98500.

📒 Files selected for processing (2)
  • packages/preact-query/src/__tests__/useMutation.test.tsx
  • packages/react-query/src/__tests__/useMutation.test.tsx

📝 Walkthrough

Walkthrough

Two nearly identical test suites are added to validate per-call callback behavior in useMutation, where mutate functions receive onSuccess and onError handlers via options parameters. Tests cover state updates from callback invocations and retry scenarios with external state mutations.

Changes

Cohort / File(s) Summary
useMutation Callback Tests
packages/preact-query/src/__tests__/useMutation.test.tsx, packages/react-query/src/__tests__/useMutation.test.tsx
Added two test cases validating per-call onSuccess/onError callback behavior: one exercising distinct handlers with different mutation variables, another testing failure-then-retry flow with shared attempt counter.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰✨ Fresh tests hop into view,
Per-call callbacks work on cue,
Success and error paths both true—
Our mutations now shine through! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring 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 name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding conditional handling and retry tests for useMutation callbacks in both react-query and preact-query packages.
Description check ✅ Passed The description follows the template structure with all required sections completed: Changes section details the two new tests and their purpose, Checklist items are marked as completed, and Release Impact correctly identifies this as dev-only.

✏️ 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/react-preact-query-useMutation-conditional-and-retry

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

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Apr 13, 2026

View your CI Pipeline Execution ↗ for commit 9a98500

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

☁️ Nx Cloud last updated this comment at 2026-04-13 19:18:43 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

@sukvvon sukvvon self-assigned this Apr 13, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 13, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 9a98500

@github-actions
Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
react full 11.99 KB (0%)
react minimal 9.02 KB (0%)

@sukvvon sukvvon merged commit cd89d6f into main Apr 13, 2026
8 checks passed
@sukvvon sukvvon deleted the test/react-preact-query-useMutation-conditional-and-retry branch April 13, 2026 19:22
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.

1 participant