
unit-test-vue-pinia
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.
- Installs
- 1.8K
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/github/awesome-copilot --skill unit-test-vue-pinia- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads unit-test-vue-pinia automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
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
- Identify the behavior boundary first: component UI behavior, composable behavior, or store behavior.
- Choose the narrowest test style that can prove that behavior.
- Set up Pinia with the least powerful option that still covers the scenario.
- Drive the test through public inputs such as props, form updates, button clicks, emitted child events, and store APIs.
- Assert observable outputs and side effects before considering any instance-level assertion.
- 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.vmonly 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.mdas 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.
const wrapper = mount(ComponentUnderTest, {
global: {
plugins: [
createTestingPinia({
createSpy: vi.fn,
}),
],
},
});
By default, actions are stubbed and spied.
Use stubActions: true (default) when the test only needs to verify whether an action was called (or not called).
Accepted minimal Pinia setups
The following are also valid and should not be flagged as incorrect:
createTestingPinia({})when the test does not assert Pinia action spy behavior.createTestingPinia({ initialState: ... })orcreateTestingPinia({ stubActions: ... })withoutcreateSpy, when the test only needs state seeding or action stubbing behavior and does not inspect generated spies.setActivePinia(createTestingPinia(...))in store/composable-focused tests (without mounting a component) when mocking/seeding dependent stores is needed.
Use createSpy: vi.fn when action spy assertions are part of the test intent.
Execute real actions only when needed
Use stubActions: false only when the test must validate the action's real behavior and side effects. Do not switch it on by default for simple "was called" assertions.
const wrapper = mount(ComponentUnderTest, {
global: {
plugins: [
createTestingPinia({
createSpy: vi.fn,
stubActions: false,
}),
],
},
});
Seed store state with initialState
const wrapper = mount(ComponentUnderTest, {
global: {
plugins: [
createTestingPinia({
createSpy: vi.fn,
initialState: {
counter: { n: 20 },
user: { name: "Leia Organa" },
},
}),
],
},
});
Add Pinia plugins through createTestingPinia
const wrapper = mount(ComponentUnderTest, {
global: {
plugins: [
createTestingPinia({
createSpy: vi.fn,
plugins: [myPiniaPlugin],
}),
],
},
});
Getter override pattern for edge cases
const pinia = createTestingPinia({ createSpy: vi.fn });
const store = useCounterStore(pinia);
store.double = 999;
// @ts-expect-error test-only reset of overridden getter
store.double = undefined;
Pure store unit tests
Prefer pure store tests with createPinia() when the goal is to validate store state transitions and action behavior without component rendering. Use createTestingPinia() only when you need stubbed dependent stores, seeded test doubles, or action spies.
beforeEach(() => {
setActivePinia(createPinia());
});
it("increments", () => {
const counter = useCounterStore();
counter.increment();
expect(counter.n).toBe(1);
});
Vue Test Utils Approach
Follow Vue Test Utils guidance: https://test-utils.vuejs.org/guide/
- Mount shallow by default for focused unit tests.
- Mount full component trees only when integration behavior is the subject.
- Drive behavior through props, user-like interactions, and emitted events.
- Prefer
findComponent(...).vm.$emit(...)for child stub events instead of touching parent internals. - Use
nextTickonly when updates are async. - Assert emitted events and payloads with
wrapper.emitted(...). - Access
wrapper.vmonly when no DOM assertion, emitted event assertion, prop assertion, or store-level assertion can express the behavior. Treat it as an exception and keep the assertion narrowly scoped.
Key Testing Snippets
Emit and assert payload:
await wrapper.find("button").trigger("click");
expect(wrapper.emitted("submit")?.[0]?.[0]).toBe("Mango Mission");
Update input and assert output:
await wrapper.find("input").setValue("Agent Violet");
await wrapper.find("form").trigger("submit");
expect(wrapper.emitted("save")?.[0]?.[0]).toBe("Agent Violet");
Test Writing Workflow
- Identify the behavior boundary to test.
- Build minimal fixture data (only fields needed by that behavior).
- Configure Pinia and required test doubles.
- Trigger behavior through public inputs.
- Assert public outputs and side effects.
- Refactor test names to describe behavior, not implementation.
Constraints and Safety
- Do not test private/internal implementation details.
- Do not overuse snapshots for dynamic UI behavior.
- Do not assert every field in large objects if only one behavior matters.
- Keep fake data deterministic; avoid random values.
- Do not claim a Pinia setup is wrong when it is one of the accepted minimal setups above.
- Do not rewrite working tests toward deeper mounting or real actions unless the behavior under test requires that extra surface area.
- Flag missing test coverage, brittle selectors, and implementation-coupled assertions explicitly during review.
Output Contract
- For
createorupdate, return the finished test code plus a short note describing the selected Pinia strategy. - For
review, return concrete findings first, then missing coverage or brittleness risks. - When the safest choice is ambiguous, state the assumption that drove the chosen test setup.
References
references/pinia-patterns.md- Pinia testing cookbook: https://pinia.vuejs.org/cookbook/testing.html
- Vue Test Utils guide: https://test-utils.vuejs.org/guide/
FAQ
What does the unit-test-vue-pinia skill do?
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.
How do I install unit-test-vue-pinia?
Run npx skills add https://github.com/github/awesome-copilot --skill unit-test-vue-pinia in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/unit-test-vue-pinia/ (personal) or .claude/skills/unit-test-vue-pinia/ (project).
Which AI agents can use unit-test-vue-pinia?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is unit-test-vue-pinia safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains unit-test-vue-pinia?
It is published by github in github/awesome-copilot, and it is an official skill from the maker of the technology it covers. It has 1,790 recorded installs.
More from github/awesome-copilot
git-commit
github/awesome-copilot
Use this skill when the user wants to make a Git commit or split changes into more than one commit. Also use it when the user types "/commit" or asks for a conventional commit. The skill examines the diff, stages the related files, writes a Conventional Commits message, and runs git commit. Do not use it when the user wants only a commit message and no commit. Do not use it to push, open a pull request, rebase, or change the commit history.
excalidraw-diagram-generator
github/awesome-copilot
Generate Excalidraw diagrams from natural language descriptions. Use when asked to "create a diagram", "make a flowchart", "visualize a process", "draw a system architecture", "create a mind map", or "generate an Excalidraw file". Supports flowcharts, relationship diagrams, mind maps, and system architecture diagrams. Outputs .excalidraw JSON files that can be opened directly in Excalidraw.
multi-stage-dockerfile
github/awesome-copilot
Create optimized multi-stage Dockerfiles for any language or framework
documentation-writer
github/awesome-copilot
Diátaxis Documentation Expert. An expert technical writer specializing in creating high-quality software documentation, guided by the principles and structure of the Diátaxis technical documentation authoring framework.
prd
github/awesome-copilot
Generate high-quality Product Requirements Documents (PRDs) for software systems and AI-powered features. Includes executive summaries, user stories, technical specifications, and risk analysis.
refactor
github/awesome-copilot
Surgical code refactoring to improve maintainability without changing behavior. Covers extracting functions, renaming variables, breaking down god functions, improving type safety, eliminating code smells, and applying design patterns. Less drastic than repo-rebuilder; use for gradual improvements.
Popular testing & qa skills
tdd
mattpocock/skills
Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
grilling
mattpocock/skills
Grill the user relentlessly about a plan, decision, or idea. Use when the user wants to stress-test their thinking, or uses any 'grill' trigger phrases.
migrate-to-shoehorn
mattpocock/skills
Migrate test files from as type assertions to @total-typescript/shoehorn. Use when user mentions shoehorn, wants to replace as in tests, or needs partial test data.
run-train
lllllllama/rigorpilot-skills
Rigor Train skill for deep learning research repositories. Use when a documented or selected training command should be run conservatively for startup verification, short-run verification, full kickoff, or resume, with command, config, seed, log, checkpoint, status, and metric evidence written to standardized trainoutputs/. Do not use for environment setup, exploratory sweeps, speculative idea implementation, or end-to-end orchestration.
test-driven-development
obra/superpowers
Use when implementing any feature or bugfix, before writing implementation code
finishing-a-development-branch
obra/superpowers
Use when implementation is complete, all tests pass, and you need to decide how to integrate the work