Skip to content

test(vue-query/useMutation): add test for outside scope warning in development mode#10238

Open
sukvvon wants to merge 2 commits intoTanStack:mainfrom
sukvvon:test/vue-query-useMutation-outside-scope-warning
Open

test(vue-query/useMutation): add test for outside scope warning in development mode#10238
sukvvon wants to merge 2 commits intoTanStack:mainfrom
sukvvon:test/vue-query-useMutation-outside-scope-warning

Conversation

@sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Mar 5, 2026

🎯 Changes

  • Add test to verify that useMutation warns when used outside of a setup() function or running effect scope in development mode.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 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 test coverage to verify a development-mode warning is emitted when a mutation hook is used outside of a setup context, ensuring consistent warning messages in dev builds.

@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

⚠️ No Changeset found

Latest commit: 9621bea

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@nx-cloud
Copy link

nx-cloud bot commented Mar 5, 2026

View your CI Pipeline Execution ↗ for commit 9621bea

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

☁️ Nx Cloud last updated this comment at 2026-03-05 05:23:11 UTC

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8523c488-95de-496c-a91e-45d1fe931e0a

📥 Commits

Reviewing files that changed from the base of the PR and between 16f0f16 and 9621bea.

📒 Files selected for processing (1)
  • packages/vue-query/src/__tests__/useMutation.test.ts

📝 Walkthrough

Walkthrough

Adds two tests in useMutation.test.ts that stub NODE_ENV to "development", spy on console.warn, invoke useMutation outside a setup function, assert the exact warning message, and restore spies/environment. No runtime logic or public signatures changed. (≈34 words)

Changes

Cohort / File(s) Summary
Development Mode Warning Tests
packages/vue-query/src/__tests__/useMutation.test.ts
Added two tests (in separate describe blocks) that mock NODE_ENV as development, spy on console.warn, call useMutation outside setup, assert the specific warning text, and restore spies/environment. No functional code changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped into tests with glee,

Listening for warnings only devs should see,
Two tiny hops, a console peep,
Restoring things before I sleep,
🧪✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a test for useMutation's outside-scope warning in development mode.
Description check ✅ Passed The description follows the required template with all key sections completed, including changes, checklist, and release impact assessment.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • 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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 5, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 72ecd8e

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/vue-query/src/__tests__/useMutation.test.ts`:
- Around line 389-402: The test sets NODE_ENV and spies on console.warn around a
call to useMutation but doesn't guarantee cleanup if the test throws; wrap the
call and assertions in a try/finally block and in finally call
vi.unstubAllEnvs() and restore the spy (e.g., warnSpy.mockRestore() or
vi.restoreAllMocks()) so environment stubs and the console.warn spy are always
restored; locate this change around the existing useMutation invocation and the
warnSpy variable in the test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5ac6d489-18ec-4d7b-92ed-dd18c904bdcc

📥 Commits

Reviewing files that changed from the base of the PR and between fe25edc and 16f0f16.

📒 Files selected for processing (1)
  • packages/vue-query/src/__tests__/useMutation.test.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant