Skip to content
cccskills
FreePublished on GitHub

frontend-testing

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

The English summary is being prepared. Showing the original description.

Works withPlaywright
See how to install

Files included (1)

  • SKILL.md4.8 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

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.

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

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.

The English summary is being prepared. Showing the original description.

aicodedecode/awesome-muse-skills28Updated Oct 10, 2026

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

The English summary is being prepared. Showing the original description.

aicodedecode/awesome-muse-skills28Updated Oct 10, 2026

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.

The English summary is being prepared. Showing the original description.

aicodedecode/awesome-muse-skills28Updated Oct 10, 2026

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

The English summary is being prepared. Showing the original description.

aicodedecode/awesome-muse-skills28Updated Oct 10, 2026

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

The English summary is being prepared. Showing the original description.

aicodedecode/awesome-muse-skills28Updated Oct 10, 2026

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

The English summary is being prepared. Showing the original description.

aicodedecode/awesome-muse-skills28Updated Oct 10, 2026

See all skills by aicodedecode

Report a problem with this skill