areas/software/frontend/skills/testing-patterns/SKILL.md
# Skill: Frontend Testing Patterns ## When to load When writing tests for components, hooks, or integration flows. ## Philosophy Test **behavior**, not implementation. A user doesn't care that you called `setState`; they care that clicking "Submit" shows a success message. ## Component Test Template ```tsx import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { UserCard } from './UserCard'; const defaultUser: User = { id: '1
npx skillsauth add sawrus/agent-guides areas/software/frontend/skills/testing-patternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
When writing tests for components, hooks, or integration flows.
Test behavior, not implementation. A user doesn't care that you called setState; they care that clicking "Submit" shows a success message.
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { UserCard } from './UserCard';
const defaultUser: User = {
id: '1', name: 'Jane Smith', email: '[email protected]', role: 'admin',
};
describe('UserCard', () => {
it('renders user information', () => {
render(<UserCard user={defaultUser} />);
expect(screen.getByText('Jane Smith')).toBeInTheDocument();
});
it('calls onEdit when edit button is clicked', async () => {
const onEdit = vi.fn();
render(<UserCard user={defaultUser} onEdit={onEdit} />);
await userEvent.click(screen.getByRole('button', { name: /edit/i }));
expect(onEdit).toHaveBeenCalledWith(defaultUser.id);
});
});
import { renderHook, act } from '@testing-library/react';
import { useCounter } from './useCounter';
it('increments count', () => {
const { result } = renderHook(() => useCounter(0));
act(() => { result.current.increment(); });
expect(result.current.count).toBe(1);
});
import { http, HttpResponse } from 'msw';
export const handlers = [
http.get('/api/users', () =>
HttpResponse.json([{ id: '1', name: 'Jane' }])
),
];
| Scenario | Test Type | |:---|:---| | Component renders | Unit (RTL) | | User interaction | Unit (RTL + userEvent) | | Data fetching states | Unit (RTL + MSW) | | Full user journey | E2E (Playwright) |
testing
QA Expert for writing E2E tests, test scenarios, test plans, and ensuring test coverage quality.
development
Expert UI/UX design intelligence for creating distinctive, high-craft, and mobile-first interfaces. Focuses on premium aesthetics, touch-first ergonomics, and Flutter performance.
development
Code Review Expert for static analysis, security auditing, architecture review, and ensuring code quality standards.
development
Babysit a GitHub pull request after creation by continuously polling review comments, CI checks/workflow runs, and mergeability state until the PR is merged/closed or user help is required. Diagnose failures, retry likely flaky failures up to 3 times, auto-fix/push branch-related issues when appropriate, and keep watching open PRs so fresh review feedback is surfaced promptly. Use when the user asks Codex to monitor a PR, watch CI, handle review comments, or keep an eye on failures and feedback on an open PR.