unit-test-vue-pinia

Write and review unit tests for Vue 3, Vitest, and Pinia codebases.

38.5k|4.9k|Updated Jun 11, 2025
One-click install
npx skills add https://github.com/github/awesome-copilot --skill unit-test-vue-pinia
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unit-test-vue-pinia
Source: https://github.com/github/awesome-copilot/tree/main/skills/unit-test-vue-pinia
Command: npx skills add https://github.com/github/awesome-copilot --skill unit-test-vue-pinia

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Writing unit tests for Vue 3 applications that use Pinia stores often leads to brittle, implementation-coupled tests or incorrect mocking setups. This Skill guides the creation and review of behavior-first tests for components, composables, and stores using Vitest, Vue Test Utils, and createTestingPinia.

Core Features & Use Cases

  • Pinia Test Setup Guidance: Applies the correct createTestingPinia configuration for each scenario, including action spies, stubActions, initialState seeding, plugin injection, and getter overrides.
  • Behavior-First Test Authoring: Drives tests through public inputs like props, DOM events, and store APIs, asserting observable outputs instead of internal implementation details.
  • Test Review: Flags brittle selectors, implementation-coupled assertions, missing coverage, and incorrect Pinia setups during code review.
  • Use Case: When adding tests for a Vue component that reads from and dispatches to a Pinia store, use this Skill to mount the component with createTestingPinia, seed initial state, trigger user-like interactions, and assert emitted events and store changes.

Quick Start

Write unit tests for my Vue 3 component that uses a Pinia store, following behavior-first patterns with Vitest and createTestingPinia.

Frequently Asked Questions about unit-test-vue-pinia

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test a Vue component that uses a Pinia store?

Mount the component with createTestingPinia registered as a global plugin, passing createSpy: vi.fn so actions are stubbed and spied. Then drive behavior through props and DOM events, and assert emitted events or action calls.

How to mock Pinia store actions in Vitest tests?

Use createTestingPinia from @pinia/testing, which stubs actions by default and wraps them in spies when createSpy: vi.fn is set. Assert calls with expect(store.action).toHaveBeenCalledTimes(n) without executing real action logic.

When should I use createPinia instead of createTestingPinia?

Use createPinia with setActivePinia for pure store unit tests that validate real state transitions and action behavior. Use createTestingPinia only when you need stubbed dependent stores, seeded state, or action spies in component tests.

How do I seed initial Pinia state in a component test?

Pass an initialState object to createTestingPinia keyed by store id, such as initialState: { counter: { n: 20 } }. The mounted component then reads the seeded values without executing any actions.

Why should tests avoid accessing wrapper.vm in Vue Test Utils?

Accessing wrapper.vm couples tests to internal component implementation, making them brittle to refactors. Prefer asserting rendered DOM, emitted events, props, or store state, and treat wrapper.vm as an exception only when no public interface expresses the behavior.

When should stubActions be set to false in Pinia testing?

Set stubActions: false only when the test must validate the real behavior and side effects inside an action. For simple call or no-call assertions, keep the default stubbing to keep tests fast and isolated.