Skip to content
Source
Sign inSign up
TanStack/query

test(svelte-query/createMutation): improve callback assertions with 'toHaveBeenNthCalledWith' and apply shorthand property syntax in FailureExample #9630

Mergedsukvvon(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/9630/headmerged by TkDodo View on GitHub

Summary 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. 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

      Cohort / File(s)Summary of Changes
      Test component cleanup
      packages/svelte-query/tests/createMutation/FailureExample.svelte
      Replaced { mutationFn: mutationFn } with { mutationFn } in createMutation options; no behavioral changes.
      Test assertions tightening
      packages/svelte-query/tests/createMutation/createMutation.test.ts
      Switched from generic toHaveBeenCalledWith to toHaveBeenNthCalledWith(1/2/3, ...) for onSuccessMock and onSettledMock; preserved expected call counts (3).

      Estimated code review effort

      🎯 2 (Simple) | ⏱️ ~10 minutes

      Poem

      I twitch my nose at tidy lines, Shorthand hops through Sveltey pines. Tests count calls—one, two, three—just so, Each nth nibble in a row. Carrots stacked, assertions neat— A rabbit’s work is clean and sweet. 🥕✨

      ✨ Finishing Touches
      • 📝 Generate Docstrings
        🧪 Generate unit tests
      • 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.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: svelte-query

    3. View your CI Pipeline Execution ↗ for commit d049df2406ca293f2fe3ce420d94bff856e91f1f

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded1m 12sView ↗
      nx run-many --target=build --exclude=examples/*...✅ Succeeded38sView ↗

      ☁️ Nx Cloud last updated this comment at 2025-09-08 12:54:56 UTC

    4. More templates

      @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@9630

      commit: d049df2

    5. Codecov 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

      Impacted file tree graph

      @@             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      -446     
      ComponentsCoverage Δ
      @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-query87.58% <ø> (ø)
      @tanstack/svelte-query-devtools∅ <ø> (∅)
      @tanstack/svelte-query-persist-client100.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 assertions

    Minor 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 onSettled

    Add 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.invocationCallOrder and also provides toHaveBeenCalledBefore/toHaveBeenCalledAfter matchers—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 shorthand

    No behavior change; this keeps the options concise and clear.

  • TkDodo merged thisccedf33

  • TkDodo closed this

  • Sign in to join this conversation.