Frontend testing
Skill yunseo-kim/agent-toolbox/catalog/skills/frontend-testing
Generate comprehensive Vitest and React Testing Library tests for frontend components, hooks, and utilities. Covers test structure, incremental workflow, async patterns, mocking strategies, and coverage goals. Use when writing or reviewing frontend tests, improving coverage, or setting up testing infrastructure for React projects.From its SKILL.md
npx -y skills add yunseo-kim/agent-toolbox --skill frontend-testingAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its file declares
Copied from the file, not written here
The file declares its own license as Sustainable Use License 1.0. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
7.9 KB, ~1.7k tokens by cl100k_base, as published. Nobody here has run it
Frontend Testing
Generate high-quality, comprehensive frontend tests following established conventions and best practices.
When to Apply
Apply this skill when:
- Writing tests for a component, hook, or utility
- Reviewing existing tests for completeness
- Working with Vitest, React Testing Library, or spec files
- Improving test coverage
- Writing unit tests or integration tests for frontend code
Do NOT apply when:
- Testing backend/API code (Python/pytest, Go, etc.)
- Writing E2E tests (Playwright/Cypress)
- Answering conceptual questions without code context
Quick Reference
Tech Stack
| Tool | Purpose |
|---|---|
| Vitest | Test runner |
| React Testing Library | Component testing |
| jsdom | Test environment |
| nock | HTTP mocking |
| TypeScript | Type safety |
Key Commands
# Run all tests
npm test # or: pnpm test / yarn test
# Watch mode
npm run test:watch
# Run specific file
npx vitest path/to/file.spec.tsx
# Generate coverage report
npx vitest --coverage
File Naming
- Test files:
ComponentName.spec.tsx(same directory as component) - Integration tests:
__tests__/directory
Test Structure Template
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
import Component from './index'
// Mock external dependencies only
vi.mock('@/service/api')
vi.mock('next/navigation', () => ({
useRouter: () => ({ push: vi.fn() }),
usePathname: () => '/test',
}))
describe('ComponentName', () => {
beforeEach(() => {
vi.clearAllMocks()
})
// Rendering tests (REQUIRED)
describe('Rendering', () => {
it('should render without crashing', () => {
render(<Component title="Test" />)
expect(screen.getByText('Test')).toBeInTheDocument()
})
})
// Props tests (REQUIRED)
describe('Props', () => {
it('should apply custom className', () => {
render(<Component className="custom" />)
expect(screen.getByRole('button')).toHaveClass('custom')
})
})
// User Interactions
describe('User Interactions', () => {
it('should handle click events', () => {
const handleClick = vi.fn()
render(<Component onClick={handleClick} />)
fireEvent.click(screen.getByRole('button'))
expect(handleClick).toHaveBeenCalledTimes(1)
})
})
// Edge Cases (REQUIRED)
describe('Edge Cases', () => {
it('should handle null data', () => {
render(<Component data={null} />)
expect(screen.getByText(/no data/i)).toBeInTheDocument()
})
it('should handle empty array', () => {
render(<Component items={[]} />)
expect(screen.getByText(/empty/i)).toBeInTheDocument()
})
})
})
Testing Workflow
Incremental Approach (Required for Multi-File)
NEVER generate all test files at once. For complex components or multi-file directories:
- Analyze & Plan: List all files, order by complexity (simple to complex)
- Process ONE at a time: Write test, run test, fix if needed, then next
- Verify before proceeding: Do NOT continue to next file until current passes
For each file:
1. Write test
2. Run: npx vitest <file>.spec.tsx
3. PASS? -> Mark complete, next file
FAIL? -> Fix first, then continue
Complexity-Based Order
Process in this order for multi-file testing:
- Utility functions (simplest)
- Custom hooks
- Simple components (presentational)
- Medium components (state, effects)
- Complex components (API, routing)
- Integration tests (index files -- last)
When to Refactor First
- Complexity > 50: Break into smaller pieces before testing
- 500+ lines: Consider splitting before testing
- Many dependencies: Extract logic into hooks first
Testing Strategy
Integration Testing First
Prefer integration testing when writing tests for a directory:
- Import real project components directly (including base components and siblings)
- Only mock: API services,
next/navigation, complex context providers - DO NOT mock base UI components (
Button,Input,Loading, etc.) - DO NOT mock sibling/child components in the same directory
Path-Level Testing
When assigned to test a directory/path, test ALL content within that path:
- Test all components, hooks, utilities in the directory
- Use incremental approach: one file at a time, verify each before proceeding
- Goal: full coverage of all files in the directory
Core Principles
1. AAA Pattern (Arrange-Act-Assert)
Every test should clearly separate:
- Arrange: Setup test data and render component
- Act: Perform user actions
- Assert: Verify expected outcomes
2. Black-Box Testing
- Test observable behavior, not implementation details
- Use semantic queries (
getByRole,getByLabelText) - Avoid testing internal state directly
- Prefer pattern matching over hardcoded strings:
// Prefer role-based queries
expect(screen.getByRole('status')).toBeInTheDocument()
// Prefer pattern matching
expect(screen.getByText(/loading/i)).toBeInTheDocument()
3. Single Behavior Per Test
Each test verifies ONE user-observable behavior:
// Good: One behavior
it('should disable button when loading', () => {
render(<Button loading />)
expect(screen.getByRole('button')).toBeDisabled()
})
// Bad: Multiple behaviors
it('should handle loading state', () => {
render(<Button loading />)
expect(screen.getByRole('button')).toBeDisabled()
expect(screen.getByText('Loading...')).toBeInTheDocument()
expect(screen.getByRole('button')).toHaveClass('loading')
})
4. Semantic Naming
Use should <behavior> when <condition>:
it('should show error message when validation fails')
it('should call onSubmit when form is valid')
it('should disable input when isReadOnly is true')
Required Test Scenarios
Always Required (All Components)
- Rendering: Component renders without crashing
- Props: Required props, optional props, default values
- Edge Cases: null, undefined, empty values, boundary conditions
Conditional (When Present)
| Feature | Test Focus |
|---|---|
useState | Initial state, transitions, cleanup |
useEffect | Execution, dependencies, cleanup |
| Event handlers | All onClick, onChange, onSubmit, keyboard |
| API calls | Loading, success, error states |
| Routing | Navigation, params, query strings |
useCallback/useMemo | Referential equality |
| Context | Provider values, consumer behavior |
| Forms | Validation, submission, error display |
Coverage Goals (Per File)
- 100% function coverage
- 100% statement coverage
- >95% branch coverage
- >95% line coverage
References
references/async-testing.md- Async operations, fake timers, and API testing patternsreferences/checklist.md- Test generation checklist and validation stepsreferences/common-patterns.md- Query priority, event handling, forms, modals, listsreferences/mocking.md- Mock patterns, Zustand stores, factory functionsreferences/workflow.md- Incremental testing workflow for multi-file directoriesassets/component-test.template.tsx- Component test templateassets/hook-test.template.ts- Hook test templateassets/utility-test.template.ts- Utility function test template
What ships with it: 9 files
55.7 KB alongside SKILL.md, 2 of them executable
assets/
- component-test.template.tsx7.0 KB
- hook-test.template.tsruns6.4 KB
- utility-test.template.tsruns4.4 KB
references/
- async-testing.md7.6 KB
- checklist.md5.0 KB
- common-patterns.md8.7 KB
- mocking.md8.5 KB
- workflow.md4.9 KB
- NOTICE.md3.3 KB