跳到主内容
智客 ZICQ

技能库 智客分类:Agent 工作流 unit-test-vue-pinia

Unit Test Vue Pinia

Vue 3 + TypeScript + Vitest + Pinia 代码库的书写和审查单元测试. 在创建或更新组件、可堆肥和存储测试时使用;用创建TestingPinia来嘲弄Pinia;应用Vue Test Utils模式;以及执行细节时执行黑盒断言.

1837 安装量

官方网址:skills.sh

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

Vue 3 + TypeScript + Vitest + Pinia 代码库的写入和审查单元测试

何时用

创建或更新组件、可堆肥和存储的测试; 以创建 TestingPinia 来嘲弄 Pinia; 应用 Vue Test Utils 模式; 执行细节上的黑框断言

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:unit-test-vue-pinia、Workflow、Core Rules、Pinia Testing Approach、Default pattern for component tests、Accepted minimal Pinia setups。 其中含规范建议的小节:分步指令、边界情况。

文件分析

文件分析:除 SKILL.md 外,正文引用了 references/pinia-patterns.md,属于带资源的技能包,这些文件按需再读。

官方 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-piniaWorkflowCore RulesPinia Testing ApproachDefault pattern for component testsAccepted minimal Pinia setupsExecute real actions only when neededSeed store state with `initialState`Add Pinia plugins through `createTestingPinia`Getter override pattern for edge casesPure store unit testsVue Test Utils Approach

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
unit-test-vue-pinia
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.
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。
指令中引用的文件 · 1
  • references/pinia-patterns.md

以下路径提取自原文;文件是否齐全请以来源仓库中的完整目录为准。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

该技能引用了附属文件,请从来源获取完整目录;仅复制 SKILL.md 可能缺少依赖。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「unit-test-vue-pinia」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-be32bb9dc16c7bed-%E5%8D%95%E4%BD%8D%E6%B5%8B%E8%AF%95-Vue-Pinia.html
请存为 .cursor/skills/unit-test-vue-pinia/SKILL.md 或 .claude/skills/unit-test-vue-pinia/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。
该技能还带 scripts/、references/、assets/ 等文件,请从 https://github.com/github/awesome-copilot 取完整目录,不要只建一个 SKILL.md。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/github/awesome-copilot' --list

npx skills add 'https://github.com/github/awesome-copilot' --skill 'unit-test-vue-pinia'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版
--- 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 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: ... })` or `createTestingPinia({ stubActions: ... })` without `createSpy`, 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. ```ts const wrapper = mount(ComponentUnderTest, { global: { plugins: [ createTestingPinia({ createSpy: vi.fn, stubActions: false, }), ], }, }); ``` ### Seed store state with `initialState` ```ts const wrapper = mount(ComponentUnderTest, { global: { plugins: [ createTestingPinia({ createSpy: vi.fn, initialState: { counter: { n: 20 }, user: { name: "Leia Organa" }, }, }), ], }, }); ``` ### Add Pinia plugins through `createTestingPinia` ```ts const wrapper = mount(ComponentUnderTest, { global: { plugins: [ createTestingPinia({ createSpy: vi.fn, plugins: [myPiniaPlugin], }), ], }, }); ``` ### Getter override pattern for edge cases ```ts 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. ```ts beforeEach(() => { setActivePinia(createPinia()); }); it("increments", () => { const counter = useCounterStore(); counter.increment(); expect(counter.n).toBe(1); }); ``` ## Vue Test Utils Approach Follow Vue Test Utils guidance: - 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 `nextTick` only when updates are async. - Assert emitted events and payloads with `wrapper.emitted(...)`. - Access `wrapper.vm` only 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: ```ts await wrapper.find("button").trigger("click"); expect(wrapper.emitted("submit")?.[0]?.[0]).toBe("Mango Mission"); ``` Update input and assert output: ```ts 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 1. Identify the behavior boundary to test. 2. Build minimal fixture data (only fields needed by that behavior). 3. Configure Pinia and required test doubles. 4. Trigger behavior through public inputs. 5. Assert public outputs and side effects. 6. 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 `create` or `update`, 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: - Vue Test Utils guide:

相关技能

Agent 工作流

Skill Creator

创造有效技能指南。 当用户想创造出新的技能(或更新现有的技能),以专业知识,工作流程,或工具集成来扩展克洛德的能力时,应该使用这种技能.

Agent 工作流

Clawdhub

使用ClawdHub CLI搜索,安装,更新并发布从taladhub.com的代理技能. 需要获取苍蝇上的新技能时使用,将安装的技能同步到最新版本或特定版本,或者发布 npm-instainddhub CLI 的新/更新的技能文件夹.

Agent 工作流

Agent Team Orchestration

管弦乐团多代理团队,任务设定周期,交接协议,审查工作流程. 使用时间: (1)建立2+特派员队伍,具有不同专业,(2)确定任务路线和生命周期(收录框_ spec_建设_审查_完成),(3)在特派员之间制定交接协议,(4)建立审查和质量关口,(5)管理特派员之间的交流和文物共享.

Agent 工作流

Superpowers

Spec-first,TDD,子代理驱动的软件开发工作流程. 当:(1)构建任何新功能或应用——触发脑暴_计划_子代理执行回路,(2)调试出一个bug或测试失败——触发系统性的根起过程,(3)用户说"让我们构建","帮助我计划","我想添加X",或"这个被打破",(4)完成一个功…