← Back to list

testing
by rafazsh
⭐ 0🍴 0📅 Dec 29, 2025
SKILL.md
name: testing description: Write tests using Vitest and Testing Library. Use when asked to write tests, add test coverage, or test a component/function.
Testing Skill
When to Use
- Writing unit tests
- Testing React components
- Adding test coverage
- Testing custom hooks
- E2E test scenarios
Test Types
| Type | Tool | Purpose |
|---|---|---|
| Unit | Vitest + Testing Library | Component rendering, hooks, utilities |
| Component | Storybook + Vitest | Browser-based interaction testing |
| Visual | Playwright | Screenshot comparison |
| E2E | Playwright | Full user journeys |
Process
-
Identify What to Test
- Component rendering
- User interactions
- State changes
- Edge cases and errors
-
Choose Query Method
- Prefer
getByRole,getByLabelText,getByText - Avoid CSS selectors and implementation details
- Prefer
-
Write Tests
- One concept per test
- Use descriptive names with
should - Test behavior, not implementation
-
Verify Coverage
- Run
npm run test:coverage - Aim for 80%+ coverage
- Run
Templates
See templates/ for test file templates.
Unit Test Template
import { render, screen } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';
import { describe, expect, it, vi } from 'vitest';
import { Component } from './index';
describe('Component', () => {
it('should render correctly', () => {
render(<Component>Test</Component>);
expect(screen.getByText('Test')).toBeInTheDocument();
});
it('should handle click events', async () => {
const handleClick = vi.fn();
render(<Component onClick={handleClick}>Click me</Component>);
await userEvent.click(screen.getByRole('button'));
expect(handleClick).toHaveBeenCalledOnce();
});
});
Hook Test Template
import { renderHook, waitFor } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { useCustomHook } from './use-custom-hook';
describe('useCustomHook', () => {
it('should return initial state', () => {
const { result } = renderHook(() => useCustomHook());
expect(result.current.value).toBe('initial');
});
});
E2E Test Template
import { expect, test } from '@playwright/test';
test.describe('Feature', () => {
test('should complete user flow', async ({ page }) => {
await page.goto('/');
await page.getByRole('button', { name: /start/i }).click();
await expect(page).toHaveURL('/next-page');
});
});
Query Priority
getByRole()- Best choicegetByLabelText()- FormsgetByText()- ContentgetByTestId()- Last resort
Checklist
- Tests focus on behavior, not implementation
- Accessible queries used (getByRole, getByLabel)
- Async operations properly awaited
- Edge cases covered
- No
.only()or.skip()in committed code - Test names use
shouldprefix
Score
Total Score
50/100
Based on repository quality metrics
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
Reviews
💬
Reviews coming soon