test(vue-query/useMutation): add tests for 'MutationFunctionContext' passed to mutationFn and callbacks - #11444
test(vue-query/useMutation): add tests for 'MutationFunctionContext' passed to mutationFn and callbacks#11444sukvvon wants to merge 5 commits into
Conversation
…passed to mutationFn and callbacks
|
View your CI Pipeline Execution ↗ for commit 921e4a1
☁️ Nx Cloud last updated this comment at |
🚀 Changeset Version Preview2 package(s) bumped directly, 23 bumped as dependents. 🟨 Minor bumps
🟩 Patch bumps
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe changes expand Vue mutation tests for ChangesMutation context
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This change adds mutation-context test coverage without changing product behavior, and no current merge-blocking risk is identified. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
size-limit report 📦
|
…ationFn' params in context test
…' for consistency
🎯 Changes
Adds test coverage for
MutationFunctionContext(the{ client, meta, mutationKey }object passed as the last argument tomutationFnand every mutation callback) invue-query'suseMutation.test.tsanduseMutation.test-d.tsx, mirroring the coverage added forreact-query/preact-query(#11440),solid-query(#11441),svelte-query(#11442), andangular-query-experimental(#11443).Runtime tests added:
onSuccessreceiving a non-undefinedonMutateResultalongsidecontextmutationFnaccessing the sameQueryClientinstance viacontext.clientcontext.mutationKeyreflecting themutationKeypassed touseMutationcontext.client.invalidateQueries()actually invalidating the cache from withinonSuccessAlso strengthens an existing test (
should only fire the per-call onSuccess for the last mutate() call), which already asserted thecontextargument's presence withexpect.anything(), to checkcontext.clientby identity instead.Type gap found, not fixed here:
mutationFn's owncontextparameter type-checks as implicitanyin this package only —onMutate/onError/onSettled/onSuccessand every per-call callback are unaffected, and runtime behavior is unaffected (core still passes the real object regardless of typing).UseMutationOptions'MaybeRefDeepwrapper is the suspected cause, unconfirmed.injectMutationinangular-query-experimental, which also takes an options-returning function, does not have this problem, so it looks vue-specific rather than inherent to the accessor pattern. The type test below excludesmutationFnfrom its assertion and documents the gap with a comment.Type tests added:
contexttyped asMutationFunctionContextfor every hook-level callback exceptmutationFn(see gap above)contexttyped asMutationFunctionContextfor every per-callmutateoptioncontext.mutationKeytyped asMutationKey | undefined✅ Checklist
pnpm run test:pr, or these tests do not apply to this pull request.🚀 Release Impact
Summary by CodeRabbit