test(svelte-query/createMutation): improve callback assertions with 'toHaveBeenNthCalledWith' and apply shorthand property syntax in FailureExample #9630
main fromrefs/pull/9630/head·merged by TkDodo View on GitHubSummary by CodeRabbit#
- Tests
- Tightened assertions to verify exact call order and arguments for mutation callbacks, improving clarity and reliability while keeping call counts unchanged. No runtime behavior impact.
- Style
- Applied object property shorthand in a test example for cleaner syntax with no semantic changes.
- Chores
- No user-facing changes or API modifications; updates are limited to tests and minor style improvements.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: svelte-query
View your CI Pipeline Execution ↗ for commit d049df2406ca293f2fe3ce420d94bff856e91f1f
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 1m 12s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 38s View ↗
☁️ Nx Cloud last updated this comment at
2025-09-08 12:54:56UTCMore templates
- @tanstack/query-example-angular-auto-refetching
- @tanstack/query-example-angular-basic
- @tanstack/query-example-angular-basic-persister
- @tanstack/query-example-angular-devtools-panel
- @tanstack/query-example-angular-infinite-query-with-max-pages
- @tanstack/query-example-angular-optimistic-updates
- @tanstack/query-example-angular-pagination
- @tanstack/query-example-angular-query-options-from-a-service
- @tanstack/query-example-angular-router
- @tanstack/query-example-angular-rxjs
- @tanstack/query-example-angular-simple
- @tanstack/query-example-solid-astro
- @tanstack/query-example-solid-basic
- @tanstack/query-example-solid-basic-graphql-request
- @tanstack/query-example-solid-default-query-function
- @tanstack/query-example-solid-simple
- @tanstack/query-example-solid-start-streaming
- @tanstack/query-example-svelte-auto-refetching
- @tanstack/query-example-svelte-basic
- @tanstack/query-example-svelte-load-more-infinite-scroll
- @tanstack/query-example-svelte-optimistic-updates
- @tanstack/query-example-svelte-playground
- @tanstack/query-example-svelte-simple
- @tanstack/query-example-svelte-ssr
- @tanstack/query-example-svelte-star-wars
- @tanstack/query-example-react-algolia
- @tanstack/query-example-react-auto-refetching
- @tanstack/query-example-react-basic
- @tanstack/query-example-react-basic-graphql-request
- @tanstack/query-example-chat
- @tanstack/query-example-react-default-query-function
- @tanstack/query-example-react-devtools-panel
- @tanstack/query-example-eslint-legacy
- @tanstack/query-example-react-infinite-query-with-max-pages
- @tanstack/query-example-react-load-more-infinite-scroll
- @tanstack/query-example-react-nextjs
- @tanstack/query-example-react-nextjs-app-prefetching
- @tanstack/query-example-nextjs-suspense-streaming
- @tanstack/query-example-react-offline
- @tanstack/query-example-react-optimistic-updates-cache
- @tanstack/query-example-react-optimistic-updates-ui
- @tanstack/query-example-react-pagination
- @tanstack/query-example-react-playground
- @tanstack/query-example-react-prefetching
- @tanstack/query-example-react-react-native
- @tanstack/query-example-react-router
- @tanstack/query-example-react-rick-morty
- @tanstack/query-example-react-shadow-dom
- @tanstack/query-example-react-simple
- @tanstack/query-example-react-star-wars
- @tanstack/query-example-react-suspense
- @tanstack/query-example-vue-2.6-basic
- @tanstack/query-example-vue-2.7-basic
- @tanstack/query-example-vue-basic
- @tanstack/query-example-vue-dependent-queries
- @tanstack/query-example-vue-nuxt3
- @tanstack/query-example-vue-persister
- @tanstack/query-example-vue-simple
@tanstack/angular-query-devtools-experimental
npm i https://pkg.pr.new/@tanstack/angular-query-devtools-experimental@9630@tanstack/angular-query-experimental
npm i https://pkg.pr.new/@tanstack/angular-query-experimental@9630@tanstack/eslint-plugin-query
npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@9630@tanstack/query-async-storage-persister
npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@9630@tanstack/query-broadcast-client-experimental
npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@9630@tanstack/query-core
npm i https://pkg.pr.new/@tanstack/query-core@9630@tanstack/query-devtools
npm i https://pkg.pr.new/@tanstack/query-devtools@9630@tanstack/query-persist-client-core
npm i https://pkg.pr.new/@tanstack/query-persist-client-core@9630@tanstack/query-sync-storage-persister
npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@9630@tanstack/react-query
npm i https://pkg.pr.new/@tanstack/react-query@9630@tanstack/react-query-devtools
npm i https://pkg.pr.new/@tanstack/react-query-devtools@9630@tanstack/react-query-next-experimental
npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@9630@tanstack/react-query-persist-client
npm i https://pkg.pr.new/@tanstack/react-query-persist-client@9630@tanstack/solid-query
npm i https://pkg.pr.new/@tanstack/solid-query@9630@tanstack/solid-query-devtools
npm i https://pkg.pr.new/@tanstack/solid-query-devtools@9630@tanstack/solid-query-persist-client
npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@9630@tanstack/svelte-query
npm i https://pkg.pr.new/@tanstack/svelte-query@9630@tanstack/svelte-query-devtools
npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@9630@tanstack/svelte-query-persist-client
npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@9630@tanstack/vue-query
npm i https://pkg.pr.new/@tanstack/vue-query@9630@tanstack/vue-query-devtools
npm i https://pkg.pr.new/@tanstack/vue-query-devtools@9630commit:
d049df2Codecov Report#
:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 89.20%. Comparing base (
af50368) to head (d049df2). :warning: Report is 2 commits behind head on main.Additional details and impacted files
@@ Coverage Diff @@ ## main #9630 +/- ## =========================================== + Coverage 45.50% 89.20% +43.69% =========================================== Files 209 18 -191 Lines 8377 176 -8201 Branches 1904 31 -1873 =========================================== - Hits 3812 157 -3655 + Misses 4118 18 -4100 + Partials 447 1 -446Components Coverage Δ @tanstack/angular-query-devtools-experimental ∅ <ø> (∅)@tanstack/angular-query-experimental ∅ <ø> (∅)@tanstack/eslint-plugin-query ∅ <ø> (∅)@tanstack/query-async-storage-persister ∅ <ø> (∅)@tanstack/query-broadcast-client-experimental ∅ <ø> (∅)@tanstack/query-codemods ∅ <ø> (∅)@tanstack/query-core ∅ <ø> (∅)@tanstack/query-devtools ∅ <ø> (∅)@tanstack/query-persist-client-core ∅ <ø> (∅)@tanstack/query-sync-storage-persister ∅ <ø> (∅)@tanstack/query-test-utils ∅ <ø> (∅)@tanstack/react-query ∅ <ø> (∅)@tanstack/react-query-devtools ∅ <ø> (∅)@tanstack/react-query-next-experimental ∅ <ø> (∅)@tanstack/react-query-persist-client ∅ <ø> (∅)@tanstack/solid-query ∅ <ø> (∅)@tanstack/solid-query-devtools ∅ <ø> (∅)@tanstack/solid-query-persist-client ∅ <ø> (∅)@tanstack/svelte-query 87.58% <ø> (ø)@tanstack/svelte-query-devtools ∅ <ø> (∅)@tanstack/svelte-query-persist-client 100.00% <ø> (ø)@tanstack/vue-query ∅ <ø> (∅)@tanstack/vue-query-devtools ∅ <ø> (∅):rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/svelte-query/tests/createMutation/createMutation.test.ts (2)
51-53: DRY up repeated nth-call assertionsMinor style: a loop keeps the expectations compact while preserving intent.
- expect(onSuccessMock).toHaveBeenNthCalledWith(1, 1) - expect(onSuccessMock).toHaveBeenNthCalledWith(2, 2) - expect(onSuccessMock).toHaveBeenNthCalledWith(3, 3) + for (const n of [1, 2, 3]) { + expect(onSuccessMock).toHaveBeenNthCalledWith(n, n) + } @@ - expect(onSettledMock).toHaveBeenNthCalledWith(1, 1) - expect(onSettledMock).toHaveBeenNthCalledWith(2, 2) - expect(onSettledMock).toHaveBeenNthCalledWith(3, 3) + for (const n of [1, 2, 3]) { + expect(onSettledMock).toHaveBeenNthCalledWith(n, n) + }Also applies to: 56-58
51-53: Assert each onSuccess runs before its corresponding onSettledAdd immediately after the existing expectations (lines 56–58):
+ // Ensure each onSuccess occurs before its corresponding onSettled + const successOrder = onSuccessMock.mock.invocationCallOrder + const settledOrder = onSettledMock.mock.invocationCallOrder + for (let i = 0; i < 3; i++) { + expect(successOrder[i]).toBeLessThan(settledOrder[i]) + }Vitest exposes
mock.invocationCallOrderand also providestoHaveBeenCalledBefore/toHaveBeenCalledAftermatchers—use whichever yields clearer intent.📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between f02388165681e525eba500112693b29e5315aaff and 3f73f8233df3d0d210c4a0e6f946013325ed3221.
📒 Files selected for processing (2)
packages/svelte-query/tests/createMutation/FailureExample.svelte(1 hunks)packages/svelte-query/tests/createMutation/createMutation.test.ts(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Preview
- GitHub Check: Test
🔇 Additional comments (1)
packages/svelte-query/tests/createMutation/FailureExample.svelte (1)
15-15: LGTM: idiomatic object property shorthandNo behavior change; this keeps the options concise and clear.
TkDodo merged thisccedf33
TkDodo closed this
sukvvon(GitHub profile, opens in a new tab) assignedsukvvon
Sign in to join this conversation.
Walkthrough#
The PR updates a Svelte test component to use object property shorthand in a createMutation call and adjusts test assertions to use nth-call checks for mock callbacks while keeping total call counts the same. No public APIs or exports are changed.
Changes#
packages/svelte-query/tests/createMutation/FailureExample.svelte{ mutationFn: mutationFn }with{ mutationFn }in createMutation options; no behavioral changes.packages/svelte-query/tests/createMutation/createMutation.test.tstoHaveBeenCalledWithtotoHaveBeenNthCalledWith(1/2/3, ...)foronSuccessMockandonSettledMock; preserved expected call counts (3).Estimated code review effort#
🎯 2 (Simple) | ⏱️ ~10 minutes
Poem#
✨ Finishing Touches
🧪 Generate unit tests
Comment `@coderabbitai help` to get the list of available commands and usage tips.