Skip to content

test({react,preact}-query/useMutation): split 'should handle conditional logic based on mutate success or failure' into separate success and error tests#10948

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

test({react,preact}-query/useMutation): split 'should handle conditional logic based on mutate success or failure' into separate success and error tests#10948
sukvvon merged 1 commit into
mainfrom
test/usemutation-split-conditional-test

Conversation

@sukvvon

@sukvvon sukvvon commented Jun 14, 2026

Copy link
Copy Markdown
Member

🎯 Changes

The should handle conditional logic based on mutate success or failure test bundled two independent scenarios into one block: a single component rendered both a submit button (mutates with shouldFail: false) and a submit fail button (mutates with shouldFail: true), then asserted the success path and the error path sequentially. These are unrelated outcomes, so each is split into its own focused test.

  • Split into should set success message from mutate callbacks when mutation succeeds (only the submit button + success assertion) and should set error message from mutate callbacks when mutation fails (only the submit fail button + error assertion).
  • 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 expectation 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
    • Refactored mutation test coverage to separately verify success and failure callback handlers in both Preact Query and React Query libraries.

…nal logic based on mutate success or failure' 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: 420be5aa-47c2-400f-b60d-018679a913f8

📥 Commits

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

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

📝 Walkthrough

Walkthrough

Two test files (react-query and preact-query) each split a single combined conditional-mutation test into two separate tests: one verifying the onSuccess callback sets the message to success: submitted successfully, and one verifying the onError callback sets the message to error: submission failed after clicking the "submit fail" button.

Changes

useMutation test refactor

Layer / File(s) Summary
react-query: split success/failure mutation tests
packages/react-query/src/__tests__/useMutation.test.tsx
Replaces the prior combined conditional-logic test with two it() blocks: a success-path test asserting success: submitted successfully via the onSuccess callback, and a failure-path test clicking "submit fail" and asserting error: submission failed via the onError callback.
preact-query: split success/failure mutation tests
packages/preact-query/src/__tests__/useMutation.test.tsx
Applies the same test split to the preact-query package — dedicated success and failure it() blocks with matching button selectors, timer advancement, and message assertions.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐇 One test split in two, hooray!
Success and failure each get their day.
The bunny clicks "submit fail" with glee,
Timers advance — what will we see?
error: submission failed, bold and free! 🎉

🚥 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 accurately summarizes the main change: splitting a combined test into two separate, focused tests for success and error paths in useMutation tests across both react-query and preact-query packages.
Description check ✅ Passed The description covers all required template sections with sufficient detail: changes are clearly explained, checklist items are completed, and release impact is properly documented as dev-only.
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-conditional-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 e915b4d

Command Status Duration Result
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 40s View ↗

☁️ Nx Cloud last updated this comment at 2026-06-14 17:02:07 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@10948

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: e915b4d

@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 4154613 into main Jun 14, 2026
11 of 12 checks passed
@sukvvon sukvvon deleted the test/usemutation-split-conditional-test branch June 14, 2026 17:03
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