Agent skill
unit-test-generation
Generate comprehensive unit tests for source files with 100% coverage target. Use when writing tests for React components, utility functions, hooks, or API routes. Supports Jest and Vitest frameworks following Pandora coding standards.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/testing/unit-test-generation
SKILL.md
Unit Test Generation Skill
Generate comprehensive unit tests for any source code with a target of 100% coverage.
When to Use
This skill activates when:
- User asks for unit tests for a file or component
- Code needs test coverage
- User mentions "test", "coverage", "jest", "vitest"
- After writing new code that needs testing
Supported File Types
- React components (
.tsx,.jsx) - Utility functions (
.ts,.js) - Custom hooks (
use*.ts,use*.tsx) - API routes (
route.ts,api/*.ts) - Classes and modules
Test Generation Process
-
Analyze the source file:
- Identify exported functions, components, hooks
- Map conditional branches and logic paths
- Note dependencies and imports
-
Generate test cases for:
- Happy path scenarios
- Edge cases (empty, null, boundary)
- Error handling paths
- All branches and conditions
-
Write test code following patterns:
- Use React Testing Library for components
- Mock external dependencies
- Use descriptive test names
- Group with describe blocks
Test File Template
import { render, screen, fireEvent } from '@testing-library/react';
import { ComponentName } from './ComponentName';
describe('ComponentName', () => {
describe('rendering', () => {
it('should render correctly with default props', () => {
render(<ComponentName />);
expect(screen.getByRole('...')).toBeInTheDocument();
});
});
describe('interactions', () => {
it('should handle click events', () => {
const onClick = jest.fn();
render(<ComponentName onClick={onClick} />);
fireEvent.click(screen.getByRole('button'));
expect(onClick).toHaveBeenCalled();
});
});
describe('edge cases', () => {
it('should handle empty props gracefully', () => {
render(<ComponentName items={[]} />);
expect(screen.getByText('No items')).toBeInTheDocument();
});
});
});
Best Practices
- Test behavior, not implementation
- Use meaningful test descriptions
- Keep tests independent and isolated
- Mock external services and APIs
- Test accessibility where applicable
- Aim for 100% branch coverage
- Follow AAA pattern (Arrange, Act, Assert)
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
riot-games
Manage Riot Games account, track stats across League, Valorant, and more
parcel
Provides comprehensive guidance for Parcel bundler including zero-configuration setup, asset handling, hot module replacement, and production builds. Use when the user asks about Parcel, needs to set up a build tool quickly, or work with Parcel's automatic configuration.
bbs
Manage issues with The Fold's CAS-native BBS (Bulletin Board System). Use for creating, updating, searching, and tracking issues. Invoke when the user wants to create tickets, find work, check issue status, or manage dependencies.
jito-bundles-and-priority-fees
Master Jito bundles for MEV protection and priority fee optimization on Solana - bundle submission, tip strategies, and transaction landing. Use for trading bots, high-priority transactions, and MEV-aware applications.
observability-monitoring-monitor-setup
You are a monitoring and observability expert specializing in implementing comprehensive monitoring solutions. Set up metrics collection, distributed tracing, log aggregation, and create insightful da
makefile-review
Didn't find tool you were looking for?