본문으로 건너뛰기
cccskills
무료GitHub에 공개

frontend-testing

Test frontend code: unit, component, E2E, visual regression, and accessibility tests with a sane pyramid. Use for reliable UI quality.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

연동 도구Playwright
설치 방법 보기

포함된 파일(1)

  • SKILL.md4.8 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Frontend Testing

A practical guide to frontend testing: the testing pyramid for UI (unit → component → E2E), visual regression, accessibility tests, and the habits that keep suites fast and trustworthy.

Overview

Frontend testing pyramid: many unit tests (pure logic: utils, hooks, reducers), component tests (render + interact: Testing Library), few E2E tests (critical user journeys: Playwright/Cypress), plus visual regression for UI fidelity and a11y checks in CI. The goal isn't coverage percentage — it's catching regressions in things users actually do.

Test behavior, not implementation: query by role/text like a user, not by component internals.

When to use

  • Setting up testing for a new frontend project.
  • Choosing between Testing Library, Playwright, Cypress, Storybook tests.
  • Flaky/slow suites needing triage.
  • Adding visual regression or a11y testing.

Core concepts

  • Unit tests (Vitest/Jest). Pure functions, utilities, hooks (renderHook), state logic. Fast (ms), numerous, no DOM needed mostly.
  • Component tests (Testing Library). Render components, fire events, assert on what the user sees: screen.getByRole('button', { name: 'Save' }). Mock network at the boundary (MSW), not internals.
  • E2E (Playwright/Cypress). Real browser, critical paths: signup, checkout, core workflows. Slow and flaky-prone — keep the count low and the value high.
  • Visual regression. Screenshot comparison (Playwright screenshots, Chromatic, Percy): catches CSS/layout breakage unit tests can't see. Baseline carefully; review diffs as a team.
  • A11y tests. axe-core in component tests and CI (jest-axe, Playwright axe) — catches missing labels, contrast, invalid ARIA automatically.
  • MSW (Mock Service Worker). Intercept network at the request level — tests exercise real fetch code with fake responses. Better than mocking fetch itself.
  • Test IDs. data-testid as a last resort; prefer role/text queries. Test IDs for elements with no good semantic query.

Practical workflow

1. Setup.

npm i -D vitest @testing-library/react @testing-library/user-event jsdom msw
npx playwright install   # E2E browsers

2. Unit test (logic).

// utils/format.test.ts
import { formatCurrency } from './format';
test('formats USD', () => expect(formatCurrency(1234.5)).toBe('$1,234.50'));

3. Component test (behavior).

import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

test('submits the form', async () => {
  const onSubmit = vi.fn();
  render(<LoginForm onSubmit={onSubmit} />);
  await userEvent.type(screen.getByLabelText(/email/i), 'a@b.c');
  await userEvent.type(screen.getByLabelText(/password/i), 'secret123');
  await userEvent.click(screen.getByRole('button', { name: /log in/i }));
  expect(onSubmit).toHaveBeenCalledWith({ email: 'a@b.c', password: 'secret123' });
});

4. E2E (critical journey).

// e2e/checkout.spec.ts
test('guest checkout', async ({ page }) => {
  await page.goto('/products/widget');
  await page.getByRole('button', { name: 'Add to cart' }).click();
  await page.getByRole('link', { name: 'Checkout' }).click();
  await expect(page.getByText('Order confirmed')).toBeVisible();
});

5. CI. Unit/component on every PR (fast); E2E on main + pre-release (slower); axe checks in both; visual regression on UI PRs.

Common pitfalls

  • Testing implementation. Asserting on state variables, mocking internal functions, snapshot-testing huge trees — brittle tests that break on refactors. Test user-observable behavior.
  • E2E for everything. 200 E2E tests = slow, flaky CI that everyone ignores. E2E the 5–10 journeys that must never break; component-test the rest.
  • Flaky selectors. CSS-class/XPath selectors break on styling changes. Role/text queries are stable and user-aligned.
  • No network mocking strategy. Tests hitting real APIs = slow + flaky + side effects. MSW or equivalent, always.
  • Sleep-based waits. await sleep(1000) = flakiness. Use proper waiting (Testing Library's findBy, Playwright's auto-waiting assertions).
  • Untested error paths. Happy-path-only suites. Test loading, error, and empty states — that's where UI bugs live.
  • 100% coverage mandates. Coverage as a target produces meaningless tests. Cover critical logic and user journeys; let the number follow.
  • Slow suites. 20-minute test runs get skipped. Parallelize, mock heavy deps, keep E2E lean. Fast feedback or no feedback.
  • Visual regression noise. Font rendering, anti-aliasing, animations cause false diffs. Stabilize (disable animations, consistent fonts) and review baselines deliberately.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Master 1Password: vaults, Watchtower, passkeys, SSH agent, CLI, and family/team administration. Use when getting full value from 1Password personally or administering it for others.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

aicodedecode/awesome-muse-skills252026년 10월 10일 업데이트

Create 3D visuals with modeling, texturing, lighting, rendering, and optimization for web and product.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

aicodedecode/awesome-muse-skills252026년 10월 10일 업데이트

Create 3D web experiences: scene setup, models, materials, lighting, animation, scroll-driven scenes, and performance budgets. Use when adding 3D to websites beyond basic demos.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

aicodedecode/awesome-muse-skills252026년 10월 10일 업데이트

Writing abstracts that get papers read — structured content, the 5-sentence core, and journal-specific constraints.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

aicodedecode/awesome-muse-skills252026년 10월 10일 업데이트

Learn effectively from courses and academies: choosing programs, studying actively, and converting courses into skills. Use when investing time/money in structured learning.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

aicodedecode/awesome-muse-skills252026년 10월 10일 업데이트

Audit designs for accessibility with WCAG checklists covering color, type, focus, motion, and content.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

aicodedecode/awesome-muse-skills252026년 10월 10일 업데이트

aicodedecode의 스킬 모두 보기

이 스킬의 문제 신고