augmnt/webdev-skills

writing-tests

Guides test creation with practical strategies for unit, integration, and e2e tests.

ソースを見る
リポジトリの原文

見出し、例、コード、表、リンク、参照画像を含む原文を表示しています。

Writing Tests

Test behavior, not implementation. Prioritize by risk.

When to Use Each Type

TypeWhatWhenTools
UnitSingle function/hookPure logic, calculationsVitest, Jest
IntegrationComponent + depsForms, data displayTesting Library
E2EFull user flowCritical pathsPlaywright

Always Test

  • Auth flows
  • Payment/checkout
  • Data mutations (create, update, delete)
  • Authorization rules
  • Critical business logic

Rarely Test

  • Static content
  • Third-party internals
  • Pure styling

File Organization

src/components/Button/
├── Button.tsx
└── Button.test.tsx      # Colocated

e2e/                     # E2E at root
├── auth.spec.ts
└── checkout.spec.ts

Patterns

Arrange-Act-Assert

typescript
test('increments on click', () => {
  // Arrange
  render(<Counter initial={0} />)
  // Act
  fireEvent.click(screen.getByRole('button'))
  // Assert
  expect(screen.getByText('1')).toBeInTheDocument()
})

Query Priority (best → worst)

  1. getByRole - semantic, accessible
  2. getByLabelText - form inputs
  3. getByText - content
  4. getByTestId - last resort

Test Behavior, Not Implementation

typescript
// ❌ Implementation
expect(component.state.isOpen).toBe(true)

// ✅ Behavior
expect(screen.getByRole('dialog')).toBeVisible()

Minimum Viable Testing

If time-constrained:

  1. E2E for happy paths (covers most ground)
  2. Unit for complex logic (catches edge cases)
  3. Integration for critical components (forms, data)

Advanced Patterns

For API mocking, test fixtures, and coverage guidance, see MOCKING.md.

同じリポジトリから

関連する Skills

すべての Skills
augmnt
コミュニティ

organizing-project-files

Provides file organization conventions for React and Next.js projects. Use when creating new files, components, hooks, utilities, or services. Triggers on questions like "where should this go?", "where do I put this?", or when deciding between colocating vs grouping files.

導入数
1
GitHub Stars
1
更新日
1月24日
augmnt
コミュニティ

reviewing-code

Provides structured code review with prioritized feedback. Use when reviewing PRs, analyzing code quality, checking for bugs, or auditing changes. Triggers on "review this", "check this code", PR reviews, or code quality questions.

導入数
1
GitHub Stars
1
更新日
1月24日
augmnt
コミュニティ

using-cli-tools

Enforces CLI tool usage over web dashboards for reproducibility and scriptability. Use when working with Git/GitHub, Supabase, Vercel, Netlify, Cloudflare, AWS, Stripe, Prisma, Docker, or any cloud service. Triggers on deployments, database operations, migrations, PRs, issues, webhooks, or environment management.

導入数
1
GitHub Stars
1
更新日
1月24日
augmnt
コミュニティ

writing-commits

Generates commit messages and PR descriptions following Conventional Commits. Use when committing code, writing PR titles, reviewing git history, or when asked to describe changes. Triggers on git commit, PR creation, or changelog generation.

導入数
1
GitHub Stars
1
更新日
1月24日