Skip to content

test(svelte-query/createMutation): add tests for 'MutationFunctionContext' passed to mutationFn and callbacks - #11442

Merged
sukvvon merged 1 commit into
mainfrom
test/svelte-mutation-context-coverage
Sep 8, 2026
Merged

test(svelte-query/createMutation): add tests for 'MutationFunctionContext' passed to mutationFn and callbacks#11442
sukvvon merged 1 commit into
mainfrom
test/svelte-mutation-context-coverage

Conversation

@sukvvon

@sukvvon sukvvon commented Sep 8, 2026

Copy link
Copy Markdown
Member

🎯 Changes

Adds test coverage for MutationFunctionContext (the { client, meta, mutationKey } object passed as the last argument to mutationFn and every mutation callback) in svelte-query's createMutation.svelte.test.ts and createMutation.test-d.ts, mirroring the coverage added for react-query/preact-query (#11440) and solid-query (#11441).

createMutation.svelte.test.ts had zero existing context assertions, so this adds 5 runtime tests (one more than react/preact/solid) — the extra one covers a per-call onSuccess context, which in the other adapters was already incidentally covered by an existing test but has no equivalent here:

  • hook-level onSuccess receiving a non-undefined onMutateResult alongside context
  • mutationFn accessing the same QueryClient instance via context.client
  • context.mutationKey reflecting the mutationKey passed to createMutation
  • context.client.invalidateQueries() actually invalidating the cache from within onSuccess
  • a per-call onSuccess receiving the same QueryClient instance via context

Each new runtime test renders a small dedicated .svelte component (SuccessContext.svelte, InvalidateFromContext.svelte, PerCallSuccess.svelte, MutationFnContext.svelte), following this file's existing one-component-per-scenario convention.

Type tests added:

  • context typed as MutationFunctionContext for mutationFn and every hook-level callback
  • context typed as MutationFunctionContext for every per-call mutate option
  • context.mutationKey typed as MutationKey | undefined

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 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
    • Expanded coverage for mutation callback behavior, including success handling, per-call callbacks, mutation keys, and context propagation.
    • Added validation for accessing query data and invalidating queries through the query client context.
    • Added type checks confirming mutation context is available to mutation functions and callbacks, with correct mutation-key typing.

@nx-cloud

nx-cloud Bot commented Sep 8, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 9a99c5c

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

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

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

2 package(s) bumped directly, 23 bumped as dependents.

🟨 Minor bumps

Package Version Reason
@tanstack/query-core 5.102.8 → 5.103.0 Changeset
@tanstack/svelte-query 6.1.48 → 6.2.0 Changeset
@tanstack/angular-query-experimental 5.102.8 → 5.103.0 Dependent
@tanstack/angular-query-persist-client 5.102.8 → 5.103.0 Dependent
@tanstack/eslint-plugin-query 5.102.8 → 5.103.0 Dependent
@tanstack/preact-query 5.102.8 → 5.103.0 Dependent
@tanstack/preact-query-devtools 5.102.8 → 5.103.0 Dependent
@tanstack/preact-query-persist-client 5.102.8 → 5.103.0 Dependent
@tanstack/query-async-storage-persister 5.102.8 → 5.103.0 Dependent
@tanstack/query-broadcast-client-experimental 5.102.8 → 5.103.0 Dependent
@tanstack/query-devtools 5.102.8 → 5.103.0 Dependent
@tanstack/query-persist-client-core 5.102.8 → 5.103.0 Dependent
@tanstack/query-sync-storage-persister 5.102.8 → 5.103.0 Dependent
@tanstack/react-query 5.102.8 → 5.103.0 Dependent
@tanstack/react-query-devtools 5.102.8 → 5.103.0 Dependent
@tanstack/react-query-next-experimental 5.102.8 → 5.103.0 Dependent
@tanstack/react-query-persist-client 5.102.8 → 5.103.0 Dependent
@tanstack/solid-query 5.102.8 → 5.103.0 Dependent
@tanstack/solid-query-devtools 5.102.8 → 5.103.0 Dependent
@tanstack/solid-query-persist-client 5.102.8 → 5.103.0 Dependent
@tanstack/svelte-query-devtools 6.1.48 → 6.2.0 Dependent
@tanstack/svelte-query-persist-client 6.1.48 → 6.2.0 Dependent
@tanstack/vue-query 5.102.8 → 5.103.0 Dependent
@tanstack/vue-query-devtools 6.1.48 → 6.2.0 Dependent

🟩 Patch bumps

Package Version Reason
@tanstack/lit-query 0.2.20 → 0.2.21 Dependent

@sukvvon sukvvon self-assigned this Sep 8, 2026
@coderabbitai

coderabbitai Bot commented Sep 8, 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 59d25a90-1b8a-41dd-a18b-7def336b321f

📥 Commits

Reviewing files that changed from the base of the PR and between e57f816 and 9a99c5c.

📒 Files selected for processing (6)
  • packages/svelte-query/tests/createMutation/InvalidateFromContext.svelte
  • packages/svelte-query/tests/createMutation/MutationFnContext.svelte
  • packages/svelte-query/tests/createMutation/PerCallSuccess.svelte
  • packages/svelte-query/tests/createMutation/SuccessContext.svelte
  • packages/svelte-query/tests/createMutation/createMutation.svelte.test.ts
  • packages/svelte-query/tests/createMutation/createMutation.test-d.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Added Svelte mutation tests for MutationFunctionContext. The tests cover callback context values, mutation-key propagation, QueryClient access, query invalidation, per-call success callbacks, and related TypeScript types.

Changes

Mutation context coverage

Layer / File(s) Summary
Callback context type assertions
packages/svelte-query/tests/createMutation/createMutation.test-d.ts
Added type assertions for MutationFunctionContext in mutation functions, hook callbacks, per-call callbacks, and mutation keys.
Context-aware mutation fixtures
packages/svelte-query/tests/createMutation/*.svelte
Added Svelte components that test QueryClient context access, success callbacks, query invalidation, mutation-function context, and per-call success callbacks.
Runtime context behavior tests
packages/svelte-query/tests/createMutation/createMutation.svelte.test.ts
Added runtime tests for callback context values, mutation-key propagation, QueryClient access, query invalidation, and per-call success callbacks.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 9a99c

This change expands Svelte Query mutation-context test coverage without changing published runtime code or release behavior. No current merge-blocking risk is identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding Svelte Query createMutation tests for MutationFunctionContext in mutation functions and callbacks.
Description check ✅ Passed The description follows the required template, explains the runtime and type-test changes, documents the release impact, and completes the checklist.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
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.
✨ 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/svelte-mutation-context-coverage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@pkg-pr-new

pkg-pr-new Bot commented Sep 8, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 9a99c5c

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
react full 11.85 KB (0%)
react minimal 8.84 KB (0%)

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