agentleFS
LeonxLJXLeonxLJX/web-engineer-skills/skills/frontend-testing-strategy/SKILL.md

frontend-testing-strategy

Skill0 starsChanged 2 months agoMITView on GitHub

What to test at each layer of a frontend app — and what to leave to the type system and CI. Vitest/RTL/playwright boundaries, test-writing rules that keep suites fast and trusted. Use when adding tests, fixing a flaky suite, or deciding coverage strategy.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Test behavior through the public API, not internals (no asserting on private state shape).

    line 31

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Frontend testing strategy

The pyramid, corrected

       E2E (few, happy paths + money paths)
      ──── Integration (component + real store/router)
     ────── Unit (pure logic: hooks, reducers, utils)
    ──────── Types + lint (catch the rest for free)
  • Types catch the "undefined is not a function" class — don't write tests for what tsc --strict already proves.
  • E2E is the most expensive and flakiest layer: reserve it for the journeys whose breakage loses users or money.

Unit: pure logic only

Hooks, reducers, formatters, parsers — anything with inputs/outputs and no DOM:

test('discount applies only above threshold', () => {
  expect(priceAfterDiscount(100, { threshold: 50, pct: 10 })).toBe(90)
  expect(priceAfterDiscount(40, { threshold: 50, pct: 10 })).toBe(40)
})
  • Test behavior through the public API, not internals (no asserting on private state shape).
  • Edge cases are the product: empty, one, many, huge, unicode, timezone boundaries.

Integration: the workhorse

Render the component with its real providers (store, router, i18n) — mock only the network:

test('adds item and shows total', async () => {
  render(<Cart />, { wrapper: TestProviders })
  await user.click(screen.getByRole('button', { name: /add/i }))
  expect(await screen.findByText('$19.00')).toBeVisible()
})
  • Query by role/name (what users perceive), never by class/test-id-first.
  • findBy for async UI; never arbitrary waitFor timeouts.

E2E: few and vital

  • Happy path + payment/auth/delete flows. Stable selectors (data-testid only where roles don't exist).
  • One environment, seeded data, parallel-safe. If a test can't say which user journey it protects, delete it.

Flakiness is a bug, not weather

  1. Re-run failing test 10× locally (--repeat) — flaky = fix or quarantine same-day.
  2. Usual suspects: uncontrolled time/random (inject clocks/seed), animation races (disable motion in tests), network races (mock at the boundary, await explicit states), test-order coupling.
  3. No sleep() in tests. Ever. Await the observable state.

The metrics that matter

  • Coverage is a smoke detector, not a goal: 80% of changed code beats 60% global vanity.
  • Track time-to-feedback (target: unit+integration < 60s locally) — slow suites get skipped, skipped suites rot.
  • Mutation-style spot checks on critical utils: would the test fail if the logic broke?

Definition of done (agent checklist)

  • New logic has tests at the lowest sufficient layer
  • Queries by role/label; async via findBy
  • No sleeps, no test-order coupling, no network beyond the mock boundary
  • Flaky tests quarantined with an owner and a deadline
  • PR diff covered where it matters (money/auth/data)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.