
Unit Test Vue Pinia
Apply cookbook-aligned Vitest and Vue Test Utils patterns for Pinia stores in component tests without fighting stubbed actions.
Install
npx skills add https://github.com/github/awesome-copilot --skill unit-test-vue-piniaWhat is this skill?
- Mount components with createTestingPinia and vi.fn createSpy per @pinia/testing cookbook
- Documents when to set stubActions: false to run real store action logic in tests
- Shows initialState seeding for counter and profile stores before mount
- Pattern to grab useStore(pinia) and assert increment was called with toHaveBeenCalledTimes
- Aligned with awesome-copilot snippets for copy-paste test setup
Adoption & trust: 1.5k installs on skills.sh; 34.6k GitHub stars; 3/3 security scanners passed (skills.sh audits).
Recommended Skills
Agent Browservercel-labs/open-agents
Tddmattpocock/skills
Use My Browserxixu-me/skills
Test Driven Developmentobra/superpowers
Verification Before Completionobra/superpowers
Webapp Testinganthropics/skills
Journey fit
Primary fit
Ship/testing is the primary shelf because the skill exists to write and structure unit/component tests, not to design UI or deploy infrastructure. Testing subphase matches Pinia-focused examples: createTestingPinia mounts, spies, initialState seeding, and action assertions.
Common Questions / FAQ
Is Unit Test Vue Pinia safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - Unit Test Vue Pinia
# Pinia Testing Snippets (Cookbook-Aligned) Use these patterns directly when writing tests with `@pinia/testing`. ## Component mount with `createTestingPinia` ```ts import { mount } from "@vue/test-utils"; import { createTestingPinia } from "@pinia/testing"; import { vi } from "vitest"; const wrapper = mount(ComponentUnderTest, { global: { plugins: [ createTestingPinia({ createSpy: vi.fn, }), ], }, }); ``` ## Execute real actions Use this only when behavior inside the action must run. If the test only checks call/no-call expectations, keep default stubbing (`stubActions: true`). ```ts const wrapper = mount(ComponentUnderTest, { global: { plugins: [ createTestingPinia({ createSpy: vi.fn, stubActions: false, }), ], }, }); ``` ## Seed starting state ```ts const wrapper = mount(ComponentUnderTest, { global: { plugins: [ createTestingPinia({ createSpy: vi.fn, initialState: { counter: { n: 10 }, profile: { name: "Sherlock Holmes" }, }, }), ], }, }); ``` ## Use store in test and assert action call ```ts const pinia = createTestingPinia({ createSpy: vi.fn }); const store = useCounterStore(pinia); store.increment(); expect(store.increment).toHaveBeenCalledTimes(1); ``` ## Add plugin under test ```ts const wrapper = mount(ComponentUnderTest, { global: { plugins: [ createTestingPinia({ createSpy: vi.fn, plugins: [myPiniaPlugin], }), ], }, }); ``` ## Override and reset getters for edge tests ```ts const pinia = createTestingPinia({ createSpy: vi.fn }); const store = useCounterStore(pinia); store.double = 42; expect(store.double).toBe(42); // @ts-expect-error test-only reset store.double = undefined; ``` --- name: unit-test-vue-pinia category: testing description: 'Write and review unit tests for Vue 3 + TypeScript + Vitest + Pinia codebases. Use when creating or updating tests for components, composables, and stores; mocking Pinia with createTestingPinia; applying Vue Test Utils patterns; and enforcing black-box assertions over implementation details.' --- # unit-test-vue-pinia Use this skill to create or review unit tests for Vue components, composables, and Pinia stores. Keep tests small, deterministic, and behavior-first. ## Workflow 1. Identify the behavior boundary first: component UI behavior, composable behavior, or store behavior. 2. Choose the narrowest test style that can prove that behavior. 3. Set up Pinia with the least powerful option that still covers the scenario. 4. Drive the test through public inputs such as props, form updates, button clicks, emitted child events, and store APIs. 5. Assert observable outputs and side effects before considering any instance-level assertion. 6. Return or review tests with clear behavior-oriented names and note any remaining coverage gaps. ## Core Rules - Test one behavior per test. - Assert observable input/output behavior first (rendered text, emitted events, callback calls, store state changes). - Avoid implementation-coupled assertions. - Access `wrapper.vm` only in exceptional cases when there is no reasonable DOM, prop, emit, or store-level assertion. - Prefer explicit setup in `beforeEach()` and reset mocks every test. - Use checked-in reference material in `references/pinia-patterns.md` as the local source of truth for standard Pinia test setups. ## Pinia Testing Approach Use `references/pinia-patterns.md` first, then fall back to Pinia's testing cookbook when the checked-in examples do not cover the case. ### Default pattern for component tests Use `createTestingPinia` as a global plugin while mounting. Prefer `createSpy: vi.fn` as the default for consistency and easier action-spy assertions. ```ts const wrapper = mount(ComponentUnderTest, { global: { plugins: [ createTestingPinia({ createSpy: vi.fn, }), ], }, }); ``` By default, actions are stubbed and sp