Skip to content

test(svelte-query/createMutation): add test for recreating observer when 'queryClient' changes#10244

Open
sukvvon wants to merge 1 commit intoTanStack:mainfrom
sukvvon:test/svelte-query-createMutation-dynamic-queryClient
Open

test(svelte-query/createMutation): add test for recreating observer when 'queryClient' changes#10244
sukvvon wants to merge 1 commit intoTanStack:mainfrom
sukvvon:test/svelte-query-createMutation-dynamic-queryClient

Conversation

@sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Mar 5, 2026

🎯 Changes

Add a test for createMutation to verify that the MutationObserver is recreated when the provided queryClient changes at runtime.

This covers createMutation.svelte.ts lines 41 and 61 (watchChanges callbacks for client/observer changes), improving line coverage from 89.47% to 100%.

✅ 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 case verifying mutation observer recreation and state reset when the underlying query client changes.

@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

⚠️ No Changeset found

Latest commit: a1a1c30

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@nx-cloud
Copy link

nx-cloud bot commented Mar 5, 2026

View your CI Pipeline Execution ↗ for commit a1a1c30

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

☁️ Nx Cloud last updated this comment at 2026-03-05 08:58:35 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 5, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 9ff94ac

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 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: c8874c39-ec56-4c0a-b8f5-a48fe28ca35e

📥 Commits

Reviewing files that changed from the base of the PR and between fe25edc and a1a1c30.

📒 Files selected for processing (1)
  • packages/svelte-query/tests/createMutation/createMutation.svelte.test.ts

📝 Walkthrough

Walkthrough

A new test case is added to verify that mutations properly recreate their observer when the underlying QueryClient dependency changes, validating reactive behavior across client swaps.

Changes

Cohort / File(s) Summary
Test Case Addition
packages/svelte-query/tests/createMutation/createMutation.svelte.test.ts
Adds test "should recreate observer when queryClient changes" with imports (flushSync, QueryClient, createMutation, withEffectRoot). Test verifies mutation observer recreation by constructing two QueryClient instances, binding mutation to stateful client, performing mutation, advancing timers, verifying success, swapping client, flushing render queue, and confirming mutation resets to idle state with undefined data.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A test hops in with client swaps in sight,
Observer recreation, dancing left and right,
When QueryClient changes, mutations reset true,
The reactive magic—now verified for you!
Flutter, flush, and verify the way,

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding a test for observer recreation when queryClient changes in createMutation.
Description check ✅ Passed The description includes all required sections (Changes, Checklist, Release Impact) with complete information about the test addition, coverage improvement, and confirmation of checklist items.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

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