LabHub

Blog

Frontend Testing 2025 — Vitest, Jest, Bun, Testing Library, Playwright, Storybook, MSW, Visual Regression, AI (S6 E11)

한국어English日本語

Prologue — why the testing stack got easier

Three things changed in 2024–2025 that simplified frontend testing:

  1. Vitest matured and absorbed most Jest users. Speed + ESM-native + Vite-integration compound.
  2. Playwright became boring in the good sense — it just works, across browsers, on CI, with great tooling.
  3. AI-generated tests moved from gimmick to "reasonable first pass" — Cursor, Continue, Claude Code can write competent tests.

This post is about what to actually write in 2026, and in what proportions.


1. The testing pyramid is still right

The 1:10:100 pyramid (e2e : integration : unit) is still the right shape. What changed:

Anti-pattern: inverted pyramid (lots of e2e, few units) — brittle, slow, expensive.


2. Unit tests — Vitest is the answer

Why Vitest won

Minimal setup

// vitest.config.ts
import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'
export default defineConfig({
  plugins: [react()],
  test: {
    globals: true,
    environment: 'happy-dom',
    setupFiles: ['./test/setup.ts'],
  },
})

When Jest is still OK

Bun test


3. Component tests — Testing Library + Storybook 8

Testing Library

Storybook 8 (2024 release) + Test Runner

Pattern: write the story first, test the story. One file, three uses: docs, unit test, visual regression.


4. Integration tests — MSW is the glue

Mock Service Worker (MSW) intercepts fetch calls at the network layer. Same mocks work in:

// mocks/handlers.ts
import { http, HttpResponse } from 'msw'
export const handlers = [
  http.get('/api/users', () => HttpResponse.json([{ id: 1, name: 'Alice' }])),
]

Benefit: your test fixtures match your dev fixtures match your docs fixtures. One source of truth.


5. E2E — Playwright is the default

Why Playwright

Playwright practices

Cypress

Bun-native e2e


6. Visual regression — Chromatic, Percy, Loki

Pattern: on every PR, visual regression runs against your Storybook preview. Bot comments with visual diffs.

Caveat: too many false positives (tiny AA diffs) → team ignores → signal loss. Tune thresholds early.


7. A11y testing — built into every layer

Goal: accessibility failures become build failures, not "someone else's job."


8. Contract tests — Zod + typed API

With tRPC/GraphQL/OpenAPI, contract tests are mostly automatic. For REST:


9. Performance testing

Tie performance budgets into CI so you don't ship an LCP regression.


10. AI-augmented testing

What works in 2026:

What doesn't yet work:

Rule: AI writes the first draft, human reviews and tightens.


11. Flakiness — the enemy

Flaky tests destroy team trust. Fixes:

Key metric: flake rate < 1%. Above that, people ignore CI failures.


12. Coverage — a tool, not a goal


13. The 2026 ideal stack

LayerTool
UnitVitest
ComponentTesting Library + Storybook 8 + Vitest
Network mocksMSW
Visual regressionChromatic
E2EPlaywright
A11yaxe-core everywhere
ContractZod + OpenAPI codegen
PerformanceLighthouse CI

12-item checklist

  1. Unit tests run under 10 seconds for a PR?
  2. E2E runs under 3 minutes with sharding?
  3. Flake rate under 1%?
  4. Every component has a Storybook story?
  5. Visual regression runs per PR?
  6. A11y failures fail build?
  7. MSW used for all network mocking?
  8. Contract tests generated, not handwritten?
  9. Performance budget in CI?
  10. Coverage thresholds set per directory?
  11. Test runner integrated with IDE (VSCode/WebStorm)?
  12. Test writing included in AI pair-programming workflow?

10 anti-patterns

  1. Testing implementation details (checking CSS classes).
  2. Too many e2e tests — pyramid inverted.
  3. setTimeout in tests.
  4. Real API calls in unit tests.
  5. Visual regression with zero tolerance — every tiny pixel change triggers.
  6. 100% coverage as goal — drives useless tests.
  7. Shared mutable state across tests.
  8. Large beforeAll setup — test order dependence.
  9. Snapshots without review — green-pass hides real regressions.
  10. Flaky tests "fixed" by retrying 3× — masks root cause.

Next episode

Season 6 Episode 12: Frontend CI/CD & Deployment 2025 — GitHub Actions, Turborepo Remote Cache, Vercel, Netlify, Cloudflare, preview environments, canary, feature flags, SLSA/SBOM.

— End of Frontend Testing.

Comments

No comments yet.

Sign in to leave a comment