Agent skill
gen-test
Generate a Vitest test file for a given source file, following project testing conventions
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/gen-test
SKILL.md
gen-test
Generate a Vitest test file for the specified source file. The test file must be co-located with the source file (e.g., foo.ts -> foo.test.ts).
Arguments
The user will provide a file path or describe the module to test.
Component tests (anything that renders JSX)
- The very first line must be
// @vitest-environment jsdom— no blank lines above it - Use
@testing-library/reactfor rendering and querying (render,screen) - Use
@testing-library/jest-dommatchers (e.g.,toHaveTextContent,toBeInTheDocument) - Query by accessible roles (
getByRole,getByLabelText) rather than test IDs - Next.js pages/layouts use
export default— import accordingly
Example shape:
// @vitest-environment jsdom
import { render, screen } from '@testing-library/react'
import MyPage from './page'
describe(`MyPage`, () => {
it(`should render the heading`, () => {
render(<MyPage />)
expect(screen.getByRole(`heading`)).toHaveTextContent(`Expected text`)
})
})
API route tests (anything under src/app/api/)
- Do NOT add the jsdom pragma
- Call route handler functions (
GET,POST, etc.) directly — they return a standardResponse - Use the Drizzle
dbinstance directly for database assertions - Clean up database state in
beforeEach - Use
@/dband@/const/...path aliases for imports
Example shape:
import { db } from '@/db'
import { myTable } from '@/db/schema'
import { GET } from './route'
beforeEach(async () => {
await db.delete(myTable)
})
describe(`/api/my-endpoint`, () => {
it(`should return success`, async () => {
const response = await GET()
expect(response.status).toBe(200)
expect(await response.json()).toEqual({ success: true })
})
})
General conventions
- Use backtick strings for
describeanditlabels (not single/double quotes) - Follow AAA pattern: Arrange, Act, Assert (with blank lines separating each phase when all three are present)
- Use descriptive test names:
it('returns 404 when resource not found') - Named exports only — no default exports (except Next.js page/layout components)
- One
describeblock per logical unit; nest when testing sub-behaviors
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?