testing

Guides writing and auditing Vitest tests with an anti-green-bar verification mindset.

Updated Jul 28, 2026
One-click install
npx skills add https://github.com/human-centric-engineering/resparkable --skill testing-human-centric-engineering
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: testing
Source: https://github.com/human-centric-engineering/resparkable/tree/main/.claude/skills/testing
Command: npx skills add https://github.com/human-centric-engineering/resparkable --skill testing-human-centric-engineering

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Tests that pass but verify nothing (green-bar tests) give false confidence and hide real bugs. This Skill enforces a discipline where every test proves what the code does — transformations, side effects, and contracts — rather than what mocks return, and routes test work into the right workflow or agent. ## Core Features & Use Cases - Anti-green-bar lens: A per-test checklist that detects weak assertions (e.g. only toBeDefined()), mock-proving tests, and missing side-effect verification, with rules for distinguishing code bugs from test bugs. - Tool routing: Maps each situation (branch changes, coverage buildout, PR audits, legacy cleanup, one-off tests) to the right command (/test-plan, /test-write, /test-review, /test-fix, /test-coverage, /test-triage) or the test-engineer agent. - Stack patterns and templates: Ready-made Vitest patterns for API routes with mocked Prisma and auth guards, React Testing Library component tests, and complexity-tiered templates (simple, medium, complex, component). - Use Case: When asked to add tests for a modified API route, apply the lens to assert the route strips sensitive fields and shapes the response envelope — not just that mocked Prisma data comes back — then validate with npm test, npm run validate, and coverage gates. ## Quick Start Ask the AI to write or review Vitest tests for a specific file or branch using this testing skill's anti-green-bar checklist and patterns.

Frequently Asked Questions about testing

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

FAQPage Schema
How do I write Vitest tests that don't just prove mocks work?▼

Assert values the code transformed, side effects like specific Prisma where clauses or log calls, or structural wrapping such as response envelopes. If the only possible assertion is the raw mock return value, treat it as a suspected code bug instead of shipping a vacuous test.

How to test Next.js API routes with mocked Prisma and auth in Vitest?▼

Mock withAuth and withAdminAuth from lib/auth/guards as identity functions and mock the prisma client methods with vi.mock. Then call the route handler directly with a NextRequest and a stubbed session, and assert transformations like stripped sensitive fields.

When should I fix the test versus report a code bug?▼

Treat the code as wrong when behavior contradicts documented contracts, docstrings, or Zod schemas, then write the failing test with correct expectations and flag it with a BUG comment. Fix the test when you assumed a wrong return shape, mocked incorrectly, or asserted an implementation detail.

Does this testing approach work with React component tests?▼

Yes, component tests use React Testing Library with userEvent and assert behavior such as onSubmit being called with form values, not styling or implementation details. Templates cover forms, loading states, validation errors, and mocking the Next.js router and auth client.

Why do my Vitest mocks register zero calls against the real module?▼

The global tests/setup.ts mocks several internal modules, so dedicated tests of those modules silently exercise the stub. Add vi.unmock for the module under test at the top of the file, before dependency mocks and imports, to run the real implementation.

What are the limitations of testing React Flow canvas components?▼

Inner callbacks like onConnect and node drag handlers are unreachable under a static @xyflow/react mock, capping function coverage around 55-65 percent. Focus tests on effects, save and publish handlers, dialog side effects, and conditional renders instead of chasing full function coverage.