Skip to content

docs: clarify stubActions limitations in Setup stores#3121

Open
dennybiasiolli wants to merge 1 commit intovuejs:v4from
dennybiasiolli:clarify-actions-stubbing
Open

docs: clarify stubActions limitations in Setup stores#3121
dennybiasiolli wants to merge 1 commit intovuejs:v4from
dennybiasiolli:clarify-actions-stubbing

Conversation

@dennybiasiolli
Copy link
Copy Markdown

@dennybiasiolli dennybiasiolli commented Apr 17, 2026

Summary

  • Documents that stubActions cannot intercept internal action calls in
    Setup stores, because they use closed-over references instead of the
    store proxy
  • Contrasts with Options API stores where this always routes through
    the proxy, so internal calls are stubbed as expected
  • Provides a workaround: call actions via useStore() inside the Setup
    store to make them interceptable by stubActions

Motivation

This is a common source of confusion when testing Setup stores — tests
appear to stub an action but internal calls still execute. The existing
docs had no mention of this behaviour or how to work around it.

👤 PR code is human-generated by @dennybiasiolli
🤖 PR text generated with Claude Code

Summary by CodeRabbit

  • Documentation
    • Clarified how action-stubbing behaves differently depending on store implementation patterns during tests, and the limits of intercepting internal action-to-action calls.
    • Added step-by-step guidance and a practical workaround to ensure internal action calls are routed so they can be stubbed reliably in tests.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 17, 2026

📝 Walkthrough

Walkthrough

Added a documentation section that explains how createTestingPinia's stubActions behaves differently for Setup (Composition API) stores versus Options API stores: closed-over internal action calls in Setup stores bypass the store proxy and are not stubbed, with a proxy-based workaround shown.

Changes

Cohort / File(s) Summary
Testing Documentation
packages/docs/cookbook/testing.md
Added a new section describing createTestingPinia's stubActions difference between Setup and Options API stores, explaining that closed-over internal action calls in Setup stores are not intercepted and providing a workaround (call via store proxy).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

Suggested reviewers

  • posva

Poem

🐰 In burrows of code I nibble and write,
Setup calls hide from the proxy's light,
Tap the store path, and stub will comply,
Hopping through docs to show you why. ✨🧪

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'docs: clarify stubActions limitations in Setup stores' directly and specifically describes the main change: documentation clarifying a limitation of stubActions in Setup stores.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
packages/testing/src/testing.spec.ts (1)

571-626: Consider grouping the three scenario tests under a shared describe block.

These three tests form a cohesive unit (Options intercept, Setup limitation, Setup workaround) that documents stubActions behavior on inner calls. Wrapping them in something like describe('inner action stubbing', () => { ... }) would improve test output readability and make the documented contract easier to navigate. Also, the assertions and rationale look correct and match the JSDoc note in testing.ts.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/testing/src/testing.spec.ts` around lines 571 - 626, Group the three
related tests that exercise inner action stubbing into a shared describe block
(e.g., describe('inner action stubbing', () => { ... })) to improve test output
and organization: move the it blocks that reference useCounter, useCounterSetup,
and the inline useStore (the tests titled "stubs inner actions in Options
Store", "can not stub inner actions called via closed-over references in Setup
Store (limitation)", and "stubs inner actions called via store proxy in Setup
Store (workaround)") inside a single describe, preserving their existing setup
calls to createTestingPinia, setActivePinia, and assertions so behavior and
JSDoc alignment remain unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/testing/src/testing.spec.ts`:
- Around line 571-626: Group the three related tests that exercise inner action
stubbing into a shared describe block (e.g., describe('inner action stubbing',
() => { ... })) to improve test output and organization: move the it blocks that
reference useCounter, useCounterSetup, and the inline useStore (the tests titled
"stubs inner actions in Options Store", "can not stub inner actions called via
closed-over references in Setup Store (limitation)", and "stubs inner actions
called via store proxy in Setup Store (workaround)") inside a single describe,
preserving their existing setup calls to createTestingPinia, setActivePinia, and
assertions so behavior and JSDoc alignment remain unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 45154ee6-b2e9-4825-a596-cf00c70ced39

📥 Commits

Reviewing files that changed from the base of the PR and between 01b46b9 and 2bc7c9f.

📒 Files selected for processing (2)
  • packages/testing/src/testing.spec.ts
  • packages/testing/src/testing.ts

@dennybiasiolli dennybiasiolli force-pushed the clarify-actions-stubbing branch from 2bc7c9f to 40d1e2e Compare April 17, 2026 09:44
@dennybiasiolli
Copy link
Copy Markdown
Author

Tests updated after this suggestion

🧹 Nitpick comments (1)

packages/testing/src/testing.spec.ts (1)> 571-626: Consider grouping the three scenario tests under a shared describe block.

Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
packages/testing/src/testing.spec.ts (1)

602-627: Workaround test looks good; consider reusing useCounterSetup for symmetry.

The test correctly shows that routing inner calls through useStore().increment() makes stubbing effective. As an optional nit, defining a fresh useStore here duplicates fixture setup and slightly diverges from the first two tests which reuse useCounter / useCounterSetup. You could add a doubleIncrementWithSelf to useCounterSetup instead, keeping all three scenarios on the same fixture — but since the inline store keeps the workaround self-contained and easy to read, this is purely a style preference.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/testing/src/testing.spec.ts` around lines 602 - 627, Replace the
inline store in the test with the existing fixture by adding a
doubleIncrementWithSelf action to the useCounterSetup fixture (or to useCounter
if that’s the setup used elsewhere) and then call useCounterSetup() (or
useCounter()) in this test; update the test to reference the fixture’s
doubleIncrementWithSelf and its increment so the behavior and assertions remain
the same while reusing the shared useCounterSetup/useCounter setup for symmetry
with the other tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/testing/src/testing.spec.ts`:
- Around line 602-627: Replace the inline store in the test with the existing
fixture by adding a doubleIncrementWithSelf action to the useCounterSetup
fixture (or to useCounter if that’s the setup used elsewhere) and then call
useCounterSetup() (or useCounter()) in this test; update the test to reference
the fixture’s doubleIncrementWithSelf and its increment so the behavior and
assertions remain the same while reusing the shared useCounterSetup/useCounter
setup for symmetry with the other tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 87800265-31b3-428c-9710-450a1aabaee3

📥 Commits

Reviewing files that changed from the base of the PR and between 2bc7c9f and 40d1e2e.

📒 Files selected for processing (2)
  • packages/testing/src/testing.spec.ts
  • packages/testing/src/testing.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/testing/src/testing.ts

Copy link
Copy Markdown
Member

@posva posva left a comment

Choose a reason for hiding this comment

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

Thanks but these tests are not needed. Let's remove them and instead of adding a NOTE to the jsdocs, add a sub section to https://pinia.vuejs.org/cookbook/testing.html#Customizing-behavior-of-actions that explains this behavior

@dennybiasiolli dennybiasiolli force-pushed the clarify-actions-stubbing branch from 40d1e2e to a197dce Compare April 17, 2026 11:43
@dennybiasiolli dennybiasiolli changed the title test(testing): clarify stubActions behavior and limitations for Setup stores docs: clarify stubActions limitations in Setup stores Apr 17, 2026
@dennybiasiolli
Copy link
Copy Markdown
Author

Ok done, thank you for the feedback

Copy link
Copy Markdown
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/docs/cookbook/testing.md`:
- Line 210: The sentence incorrectly suggests using this.increment() for Setup
stores; update the text to remove the this.increment() reference and clarify
that Setup stores should call actions via the store proxy (e.g.,
useStore().increment() or the specific useCounterStore().increment()) so that
stubActions affects them as expected; ensure mentions of increment(),
useStore(), useCounterStore(), Setup store, and stubActions remain consistent
with the example shown.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a7381756-b62a-40ed-ac51-9bbbab50a87a

📥 Commits

Reviewing files that changed from the base of the PR and between 40d1e2e and a197dce.

📒 Files selected for processing (1)
  • packages/docs/cookbook/testing.md

Comment thread packages/docs/cookbook/testing.md Outdated
Explains that internal action calls in Setup stores bypass stubActions
because they use closed-over references instead of the store proxy,
and documents the workaround of calling actions via the store proxy.
@dennybiasiolli dennybiasiolli force-pushed the clarify-actions-stubbing branch from a197dce to 9ccf320 Compare April 17, 2026 11:48
Copy link
Copy Markdown
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/docs/cookbook/testing.md`:
- Around line 188-191: The doc's description is contradictory: you say
store.incrementTwice() is "stubbed" and yet its internal call to increment()
"will still run"; update the text around useCounterStore(), increment(), and
incrementTwice() to separate the two cases clearly—(a) when incrementTwice()
itself is stubbed its implementation does not run and thus it will not call
increment(), and (b) when only increment() is stubbed via the store proxy,
calling incrementTwice() will run its real implementation and will invoke the
stubbed increment(); reword the example lines to reflect these two distinct
behaviors.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 40375a97-87d1-455b-8bd6-af79d0194f48

📥 Commits

Reviewing files that changed from the base of the PR and between a197dce and 9ccf320.

📒 Files selected for processing (1)
  • packages/docs/cookbook/testing.md

Comment thread packages/docs/cookbook/testing.md
@dennybiasiolli dennybiasiolli requested a review from posva April 20, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🆕 Triaging

Development

Successfully merging this pull request may close these issues.

2 participants