All skills
github avatar

/unit-test-vue-pinia

@3751155 official
by githubgithub/awesome-copilot40k stars
5,040

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.

Use this Skill: https://skilld.dev/gh/github/awesome-copilot/unit-test-vue-pinia

This session only. Nothing lands on disk.

referencespinia-patterns.md

≈455 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Pinia Testing Snippets (Cookbook-Aligned)

Use these patterns directly when writing tests with @pinia/testing.

Component mount with createTestingPinia

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).

const wrapper = mount(ComponentUnderTest, {
  global: {
    plugins: [
      createTestingPinia({
        createSpy: vi.fn,
        stubActions: false,
      }),
    ],
  },
});

Seed starting state

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

const pinia = createTestingPinia({ createSpy: vi.fn });
const store = useCounterStore(pinia);

store.increment();
expect(store.increment).toHaveBeenCalledTimes(1);

Add plugin under test

const wrapper = mount(ComponentUnderTest, {
  global: {
    plugins: [
      createTestingPinia({
        createSpy: vi.fn,
        plugins: [myPiniaPlugin],
      }),
    ],
  },
});

Override and reset getters for edge tests

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;

Source: SKILL.md on GitHub

No alerts16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill provides comprehensive instructions and best practices for testing Vue components, composables, and Pinia stores. It defines a behavior-first testing workflow and provides standardized code snippets for common testing scenarios. No security risks were identified.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    2 files scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 3751155. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 7 months ago
category
testing

README badge

README badge for github/awesome-copilot/unit-test-vue-pinia

Write and review unit tests for Vue 3 components, composables, and Pinia stores using Vitest and Vue Test Utils. Enforces behavior-first assertions, mocking with createTestingPinia, and avoids implementation-coupled test logic.

Generated from the current SKILL.md.

Does this skill cover testing Vue 3 components, composables, and Pinia stores?
Yes. The skill addresses all three: components with Vue Test Utils, composables as standalone behavior units, and stores using createTestingPinia with optional action spies and state seeding.
What testing framework does this use?
Vitest. The skill assumes Vitest is the test runner and uses vi.fn for action spies and mocking.
When should I use createTestingPinia vs createPinia?
Use createTestingPinia when you need stubbed dependent stores, seeded test doubles, or action spies in component tests. Use createPinia for pure store unit tests that validate state transitions without component rendering.
Does this skill enforce snapshot testing?
No. The skill explicitly discourages snapshots for dynamic UI behavior and prefers behavior-oriented assertions on rendered output, emitted events, and store state changes.
Can I access wrapper.vm to assert component instance details?
Only in exceptional cases when no DOM, prop, emit, or store-level assertion can express the behavior. The skill treats it as a last resort and favors black-box assertions.

Generated from the current SKILL.md. These answers refresh after source changes.