Skip to content

test({react,preact}-query/useMutation): split 'should pass meta to mutation' into separate success and error tests#10947

Merged
sukvvon merged 1 commit into
mainfrom
test/usemutation-split-meta-test
Jun 14, 2026
Merged

test({react,preact}-query/useMutation): split 'should pass meta to mutation' into separate success and error tests#10947
sukvvon merged 1 commit into
mainfrom
test/usemutation-split-meta-test

Conversation

@sukvvon

@sukvvon sukvvon commented Jun 14, 2026

Copy link
Copy Markdown
Member

🎯 Changes

The should pass meta to mutation test bundled two independent scenarios into one block: it set up two separate useMutation calls (one resolving, one rejecting) in a single component and asserted both the success-meta and error-meta paths together. These are unrelated behaviors, so each is split into its own focused test.

  • Split into should pass meta to mutation on success (only the resolving mutation + onSuccess cache callback) and should pass meta to mutation on error (only the rejecting mutation + onError cache callback).
  • Applied identically to react-query and preact-query, whose useMutation tests are kept in sync.

No assertions are lost — each new test keeps the exact expectations for its path. Both packages' useMutation suites pass.

✅ 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
    • Improved mutation test suite by refactoring into separate, focused test cases. Enhanced coverage by splitting a combined test into two dedicated scenarios for success and error flows, each specifically verifying that meta parameters are correctly passed to the corresponding mutation callbacks. Improved test clarity and maintainability.

…tation' into separate success and error tests
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e1f0ddc0-ea2e-4ecd-816b-30196d1f200c

📥 Commits

Reviewing files that changed from the base of the PR and between 63d425b and 212d0c1.

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

📝 Walkthrough

Walkthrough

The single combined useMutation meta test in both packages/react-query and packages/preact-query is replaced with two focused tests each: one verifying meta reaches the MutationCache.onSuccess handler via metaSuccessMessage, and one verifying it reaches MutationCache.onError via metaErrorMessage.

Changes

useMutation Meta Test Refactor

Layer / File(s) Summary
Success-meta test cases
packages/react-query/src/__tests__/useMutation.test.tsx, packages/preact-query/src/__tests__/useMutation.test.tsx
New dedicated tests build a QueryClient/MutationCache with an onSuccess handler reading mutation.meta?.metaSuccessMessage, trigger via a "succeed" button, assert success UI, and verify the mock is called once with the expected message.
Error-meta test cases
packages/react-query/src/__tests__/useMutation.test.tsx, packages/preact-query/src/__tests__/useMutation.test.tsx
New companion tests configure MutationCache.onError to read mutation.meta?.metaErrorMessage, render only an error trigger with isError-gated UI, trigger the error, and assert the errorTest element appears.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐇 Hop, hop — one test split in two,
Success and error each get their due!
metaSuccessMessage shines on the right,
metaErrorMessage handled with might.
Two focused tests, the warren grows bright! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: splitting a combined mutation test into separate success and error tests across both packages.
Description check ✅ Passed The description covers all key sections from the template with clear explanations of the changes, completed checklist items, and correct release impact classification.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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/usemutation-split-meta-test

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

@sukvvon sukvvon self-assigned this Jun 14, 2026
@nx-cloud

nx-cloud Bot commented Jun 14, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 212d0c1

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

☁️ Nx Cloud last updated this comment at 2026-06-14 16:55:54 UTC

@github-actions

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-new Bot commented Jun 14, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@10947

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 212d0c1

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
react full 12.11 KB (0%)
react minimal 9.08 KB (0%)

@sukvvon sukvvon merged commit 8bb5fde into main Jun 14, 2026
9 checks passed
@sukvvon sukvvon deleted the test/usemutation-split-meta-test branch June 14, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant