/quality-gates:vitest-testsfrom quality-gates
Guides writing, generating, and fixing Vitest unit/component tests with patterns for mocking, async, component queries, and proof steps.
Ships in quality-gates. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A test is worth keeping when it fails if the behaviour breaks and passes for every refactor that keeps the behaviour. Generate cases from the behaviour, not from the lines of the implementation.
environment, globals, setupFiles, aliases, restoreMocks.jest.*.For each public function, hook or component, list before writing:
Cover them with it.each when only the data differs.
describe names the unit. it names the behaviour: returns 0 for an empty cart.if, loop or try/catch inside a test.toBe for primitives, toStrictEqual for objects, toThrow(ErrorClass) or a message for errors. toBeTruthy and toBeDefined rarely prove anything.toMatchInlineSnapshot.Mock only the boundary: network, clock, randomness, filesystem, env. Never mock the unit under test or its pure helpers.
| Need | Use |
|---|---|
| Replace one method | vi.spyOn(obj, 'method') |
| Replace a module | vi.mock('./mod'). It is hoisted above imports: values it needs go in vi.hoisted(() => ...) |
| Typed access to a mock | vi.mocked(fn) |
| Time | vi.useFakeTimers(), vi.setSystemTime(date), await vi.advanceTimersByTimeAsync(ms); vi.useRealTimers() in afterEach |
| Env and globals | vi.stubEnv, vi.stubGlobal |
| HTTP | The repo's MSW handlers if present, else mock the client module |
Restore in afterEach unless the config already does.
await expect(promise).rejects.toThrow(...). Without await the test passes whatever happens.vi.waitFor or expect.poll. Never sleep.Query the way a user finds things (getByRole, getByLabelText), act with userEvent, assert on what is rendered. Do not assert on state, props or class names.
npx vitest run <path> (or the project's script).Cases: <count> covering <the list above, briefly>
Run: <command> -> <passed/failed>
Seen failing: <yes, how | no, why>
Mocked: <boundaries mocked>
Not covered: <cases left out and why>
.skip, to get to green..only in the file.Key decisions in this skill: the test boundary (unit vs integration, what to mock), a change to production code for testability, and tests that pin money, auth or a business rule.
Before acting on one, get a second opinion: call the Agent tool with model: "opus" (subagent_type Plan, read-only). Give it the decision, each option in one line, the evidence (file:line, measurements, the diff) and the constraints. Ask for a pick, the main risk of that pick, and what would change its mind. Do not send secrets or .env contents.
Advisor: <decision> -> <pick> (<agreed | overruled because ...>).Spend the strong models on judgment and the cheap ones on volume. When this skill spawns subagents with the Agent tool, set model by role:
| Role | Model | Use for |
|---|---|---|
| Think | fable (Fable 5.2), or opus when limits are tight | Plan, decompose, pick an approach. One call, read-only (subagent_type: "Plan"). |
| Execute | sonnet (Sonnet 5.5) | Write and edit code, run checks, produce the deliverable. |
| Review | opus (Opus 5.5) | Check the finished work before reporting: correctness, security, money, data loss. |
| Swarm | haiku (Haiku 5.5) | Many small parallel jobs: search, read, extract, classify, per-file scans. |
mcp__ccd_session_mgmt__get_usage (load it with ToolSearch if deferred). Use fable only when every window has room: 5-hour limit under 70% used, "Weekly · all models" under 80%, and "Weekly · Fable" (if listed) under 80%. Otherwise use opus. If the tool is missing, or its status is unavailable or not_applicable (API key, Bedrock, Vertex), use opus. Say the pick in one line: Think: <model> (5h <n>%, weekly <n>%, Fable <n>%).Lessons from earlier runs live in two files: ~/.claude/skill-lessons/vitest-tests.md (any repo) and .claude/skill-lessons/vitest-tests.md at the repo root (this repo only).
- <YYYY-MM-DD>: <do or avoid X> because <Y>. (seen: 1). When a line already says the same thing, raise its seen count and date instead of adding one. Facts about this repo go in the repo file, everything else in the user file. Keep each file under 30 lines by merging or dropping stale lessons.seen: 3: if the ashish-claude-skills source repo is open, propose the edit to plugins/quality-gates/skills/vitest-tests/SKILL.md as a diff and wait for a yes, then delete the lesson once it lands; otherwise say Lesson ready to promote: <line> in the report.Learned: <the line written | nothing>.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
10 skills in this plugin
/claude-md-syncUse after changing business logic, domain rules, data models, APIs, architecture, commands, config or dependencies, before calling the work done, to keep CLAUDE.md true to the code. Also when the user says "update CLAUDE.md", "sync the docs" or "is CLAUDE.md still right"./design-auditUse when a UI component, page or stylesheet has just been built or changed and its visual quality needs checking, when the user asks whether a screen looks right, consistent or polished, or before shipping front-end work./login-and-accessUse when writing, changing or reviewing sign-in, sign-up, logout, password reset, magic links, OAuth or SSO, MFA, sessions, cookies, JWTs, refresh tokens, roles, permissions, admin areas, multi-tenant data or any route that must know who the caller is and what they may see./personal-dataUse when writing, changing or reviewing code that stores, reads, sends, logs, exports or deletes information about people (users, customers, clients, patients, children, employees), including new database columns or tables, migrations, forms, analytics or tracking events, error reporting, third-party APIs, AI prompts, data exports, account deletion, consent, cookie banners, retention jobs, or questions about GDPR, CCPA, LGPD, DPDP or other privacy laws./playwright-testsUse when writing, generating or fixing Playwright end-to-end tests, covering a user journey in a real browser, choosing locators, handling login state or test data, or when an e2e test is flaky, slow or times out./security-code-auditUse when writing, changing or reviewing code that handles user input, forms, auth, passwords, sessions, tokens, API keys, secrets, env vars, permissions, database queries, file uploads, webhooks, payments or a new API route, or when the user asks for a security review of a diff, a file or a feature.npx claudepluginhub ashishyd/ashish-claude-skills --plugin quality-gates