Skip to content

test({react,preact}-query/useMutation): add single callback tests for 'onSuccess', 'onError', and 'onSettled' - #10487

Merged
sukvvon merged 2 commits into
mainfrom
test/react-preact-query-useMutation-single-callback
Apr 13, 2026
Merged

test({react,preact}-query/useMutation): add single callback tests for 'onSuccess', 'onError', and 'onSettled'#10487
sukvvon merged 2 commits into
mainfrom
test/react-preact-query-useMutation-single-callback

Conversation

@sukvvon

@sukvvonsukvvon commented Apr 13, 2026

Copy link
Copy Markdown
Member

🎯 Changes

  • Add 3 runtime tests for useMutation single callback cases in both react-query and preact-query:
    • should be able to call 'onSuccess' callback after successful mutate: only onSuccess callback at both useMutation and mutate level
    • should be able to call 'onError' callback after failed mutate: only onError callback at both levels
    • should be able to call 'onSettled' callback after mutate: only onSettled callback at both levels
  • Complements existing tests that verify multiple callbacks together (onSuccess + onSettled, onError + onSettled)

✅ 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

  • Enhanced test coverage for useMutation hook by adding callback invocation ordering tests to verify library-level callbacks execute before per-call callbacks for success, error, and settled scenarios across both React and Preact implementations.

@coderabbitai

coderabbitaiBot commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c8f9272c-860a-44e2-a558-3ea70ab33dd9

📥 Commits

Reviewing files that changed from the base of the PR and between 224c073 and b83e14a.

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

📝 Walkthrough

Walkthrough

Added test coverage for callback invocation ordering in useMutation hooks across React and Preact implementations. Three test cases verify that hook-level callbacks (onSuccess, onError, onSettled) execute before their corresponding per-call mutate callbacks.

Changes

Cohort / File(s)Summary
Callback ordering tests
packages/preact-query/src/__tests__/useMutation.test.tsx, packages/react-query/src/__tests__/useMutation.test.tsx
Added three test cases verifying callback invocation order in useMutation: hook-level onSuccess, onError, and onSettled execute before their per-call mutate counterparts. Tests use fake timers and validate callback sequence via accumulated arrays.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 Hops through callbacks, neat and true,
Hook runs first, then calls run through,
Order matters, sequence clear,
Tests now verify, no more fear! 🎯

🚥 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: adding single callback tests for onSuccess, onError, and onSettled in both react-query and preact-query useMutation test files.
Description check✅ PassedThe description provides a clear explanation of changes, follows the required template structure with all sections completed, and includes a properly checked release impact checklist indicating this is a dev-only change.

✏️ 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-single-callback

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

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

nx-cloudBot commented Apr 13, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit b83e14a

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

☁️ Nx Cloud last updated this comment at 2026-04-13 17:17:13 UTC

@github-actions

github-actionsBot commented Apr 13, 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

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: b83e14a

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
react full11.99 KB (0%)
react minimal9.02 KB (0%)

@sukvvon
sukvvon merged commit eccac7c into mainApr 13, 2026
8 checks passed
@sukvvon
sukvvon deleted the test/react-preact-query-useMutation-single-callback branch April 13, 2026 17:27
Ephem pushed a commit to Ephem/react-query that referenced this pull request Apr 23, 2026
… 'onSuccess', 'onError', and 'onSettled' (TanStack#10487)
* test({react,preact}-query/useMutation): add single callback tests for 'onSuccess', 'onError', and 'onSettled'
* ci: apply automated fixes
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
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