test(react-query/useMutationState): clarify assertions and improve code formatting #9611
main fromrefs/pull/9611/head·merged by TkDodo View on GitHubSummary by CodeRabbit#
- Tests
- Strengthened mutation state coverage with sequence tracking across renders.
- Adjusted timer advances to better reflect batching behavior.
- Expanded assertions to validate intermediate states and full mutation sequences.
- Ensured components render before timers advance for more reliable outcomes.
- Refined assertion styles for clearer intent and readability.
- Minor JSX/formatting cleanups within test setups.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-query
View your CI Pipeline Execution ↗ for commit 79b9ebfe4ba586a2366d02fae51fd3a4d25ce41e
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 57s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 2s View ↗
☁️ Nx Cloud last updated this comment at
2025-09-03 01:39:19UTCMore 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-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-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-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@9611@tanstack/angular-query-experimental
npm i https://pkg.pr.new/@tanstack/angular-query-experimental@9611@tanstack/eslint-plugin-query
npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@9611@tanstack/query-async-storage-persister
npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@9611@tanstack/query-broadcast-client-experimental
npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@9611@tanstack/query-core
npm i https://pkg.pr.new/@tanstack/query-core@9611@tanstack/query-devtools
npm i https://pkg.pr.new/@tanstack/query-devtools@9611@tanstack/query-persist-client-core
npm i https://pkg.pr.new/@tanstack/query-persist-client-core@9611@tanstack/query-sync-storage-persister
npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@9611@tanstack/react-query
npm i https://pkg.pr.new/@tanstack/react-query@9611@tanstack/react-query-devtools
npm i https://pkg.pr.new/@tanstack/react-query-devtools@9611@tanstack/react-query-next-experimental
npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@9611@tanstack/react-query-persist-client
npm i https://pkg.pr.new/@tanstack/react-query-persist-client@9611@tanstack/solid-query
npm i https://pkg.pr.new/@tanstack/solid-query@9611@tanstack/solid-query-devtools
npm i https://pkg.pr.new/@tanstack/solid-query-devtools@9611@tanstack/solid-query-persist-client
npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@9611@tanstack/svelte-query
npm i https://pkg.pr.new/@tanstack/svelte-query@9611@tanstack/svelte-query-devtools
npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@9611@tanstack/svelte-query-persist-client
npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@9611@tanstack/vue-query
npm i https://pkg.pr.new/@tanstack/vue-query@9611@tanstack/vue-query-devtools
npm i https://pkg.pr.new/@tanstack/vue-query-devtools@9611commit:
79b9ebfCodecov Report#
:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 84.51%. Comparing base (
c75a994) to head (79b9ebf). :warning: Report is 2 commits behind head on main.Additional details and impacted files
@@ Coverage Diff @@ ## main #9611 +/- ## =========================================== + Coverage 45.26% 84.51% +39.24% =========================================== Files 208 26 -182 Lines 8340 368 -7972 Branches 1895 108 -1787 =========================================== - Hits 3775 311 -3464 + Misses 4118 48 -4070 + Partials 447 9 -438- :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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/react-query/src/__tests__/useMutationState.test.tsx (1)
62-76: Use prefix/suffix assertions instead of exact sequence to prevent flaky tests- await vi.advanceTimersByTimeAsync(41) - expect(isMutatingArray[0]).toEqual(0) - expect(isMutatingArray[1]).toEqual(1) - expect(isMutatingArray[2]).toEqual(2) - expect(isMutatingArray[3]).toEqual(1) - expect(isMutatingArray[4]).toEqual(0) - - expect(isMutatingArray).toEqual([0, 1, 2, 1, 0]) + await vi.advanceTimersByTimeAsync(41) + // Deterministic prefix/suffix; allow batching differences in the middle. + expect(isMutatingArray.slice(0, 3)).toEqual([0, 1, 2]) + expect([4, 5]).toContain(isMutatingArray.length) + expect(isMutatingArray.at(-1)).toEqual(0)🧹 Nitpick comments (1)
packages/react-query/src/__tests__/useMutationState.test.tsx (1)
21-27: Avoid side-effects in render; record values in an effectPushing to a shared array during render is a side-effect and can behave unexpectedly (e.g., extra renders). Record on value change via an effect instead.
function IsMutating() { const isMutating = useIsMutating() - - isMutatingArray.push(isMutating) - - return null + React.useEffect(() => { + isMutatingArray.push(isMutating) + }, [isMutating]) + return null }📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📥 Commits
Reviewing files that changed from the base of the PR and between 0a35234ce48b7f8e5c81999bd309ae9311981280 and 84f819e919a6f3edbaf2f11581ca4f8c624375ed.
📒 Files selected for processing (1)
packages/react-query/src/__tests__/useMutationState.test.tsx(7 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/react-query/src/__tests__/useMutationState.test.tsx (2)
packages/vue-query/src/queryClient.ts (1)
isMutating(53-55)
packages/query-core/src/queryClient.ts (1)
isMutating(116-120)
⏰ 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 (2)
packages/react-query/src/__tests__/useMutationState.test.tsx (2)
173-177: LGTM: custom queryClient pathUsing the queryClient param with plain render (no Provider) is correct, and the assertion reads clearly.
230-235: LGTM: clearer presence assertionsSwitch to
toBeInTheDocument()improves intent without changing semantics.TkDodo merged this43049c5
TkDodo closed this
sukvvon(GitHub profile, opens in a new tab) assignedsukvvon
Sign in to join this conversation.
Walkthrough#
Test updates in packages/react-query/src/tests/useMutationState.test.tsx adjust timer advances, render timing, and assertions to capture mutation states over time. An array now records isMutating values per render, and tests validate intermediate and final sequences. Minor JSX formatting and assertion style updates are included.
Changes#
packages/react-query/src/__tests__/useMutationState.test.tsxEstimated code review effort#
🎯 2 (Simple) | ⏱️ ~10 minutes
Suggested labels#
package: react-querySuggested reviewers#
Poem#
✨ Finishing Touches
🧪 Generate unit tests
🪧 Tips
Chat#
There are 3 ways to chat with CodeRabbit:
I pushed a fix in commit <commit_id>, please review it.Open a follow-up GitHub issue for this discussion.@coderabbitaiin a new review comment at the desired location with your query.@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.Support#
Need help? Create a ticket on our support page for assistance with any issues or questions.
CodeRabbit Commands (Invoked using PR/Issue comments)#
Type
@coderabbitai helpto get the list of available commands.Other keywords and placeholders#
@coderabbitai ignoreor@coderabbit ignoreanywhere in the PR description to prevent this PR from being reviewed.@coderabbitai summaryto generate the high-level summary at a specific location in the PR description.@coderabbitaianywhere in the PR title to generate the title automatically.CodeRabbit Configuration File (
.coderabbit.yaml)#.coderabbit.yamlfile to the root of your repository.# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.jsonStatus, Documentation and Community#