# The Frontend Testing Gap

*By Bri Stanback · 2026-03-14*
*https://bristanback.com/notes/frontend-testing-gap/*

> Backend testing is a solved problem. Frontend testing for stateful, streaming, visual UIs is not. That's exactly where AI coding agents are generating the most code.

![The Frontend Testing Gap](https://bristanback.com/images/posts/frontend-testing-gap-hero.webp)

---

Here's the gap nobody's talking about: the places where AI coding agents are most productive are the places where automated testing is weakest.

Backend services have mature test infrastructure. You write a function, you write a test, you assert the output. CI catches regressions. The agent writes code, the tests verify it, the human reviews the delta. That loop works.

Frontend — specifically stateful, streaming, visual frontend — breaks every part of that loop.

## The Three Hard Properties

A chat interface has three properties that make it genuinely difficult to test:

**Stateful.** The UI depends on a sequence of events over time. Message arrives, scroll position adjusts, user scrolls up, new message arrives but scroll doesn't follow, user scrolls back down, auto-scroll resumes. The correctness of any given frame depends on everything that happened before it. You can't test a single state — you have to test a *trajectory*.

**Streaming.** Content arrives in chunks. A word at a time, sometimes a partial token split across two chunks. The DOM is being mutated continuously while the user is interacting with it. The parser has to handle markdown that's half-formed — an opening backtick with no closing backtick *yet*. The scroll container is growing while being read. The rendering has to be smooth enough that it doesn't feel like watching a terminal.

**Visual.** "It works" and "it looks right" are different assertions. The message appeared — but is it inside its container? The scroll followed — but did it jank? The input resized — but did it push the messages off screen? These are questions that a unit test literally cannot answer. You need a real browser, rendering real pixels, on a real viewport.

An AI coding agent can change the scroll logic, run the unit tests, see them pass, and ship code that breaks on every iPhone. Not because the logic is wrong — because the *visual consequence* of the logic only manifests in a rendering engine the agent never sees.

## Why This Didn't Matter Before

The frontend went through phases. Server-rendered templates were genuinely thin — fetch data, render HTML, done. Then SPAs swallowed everything: routing, state, data fetching, caching, the works. Now the pendulum is swinging back with islands and edge rendering — the *intent* is thinner frontends again, but the islands that do exist are denser than ever. Either way, the testing story was always simpler when the server owned the output. You could test "does the right HTML arrive?" without a browser.

Three things changed:

**[Islands architecture.](https://docs.astro.build/en/concepts/islands/)** Interactive components hydrate independently on otherwise static pages. Each island is a miniature application with its own state, lifecycle, and failure modes. The chat island on our site is 1,200 lines of vanilla TypeScript managing streaming SSE, markdown parsing, scroll physics, input auto-resize, and error recovery. That's not a "component." That's an application embedded in a page.

**Streaming as the default.** LLM-powered interfaces don't return a response — they stream one. Every chat UI, every AI assistant, every copilot integration is now a streaming renderer. The entire frontend industry shifted to streaming in about eighteen months and the testing infrastructure didn't follow.

**AI writing the UI code.** When a human writes the scroll handler, they test it by scrolling. They see the jank. They feel the broken behavior. When an agent writes the scroll handler, it sees the code, maybe runs a unit test, and moves on. The feedback loop that used to happen in the developer's eyes now has a gap where the eyes used to be.

## What a Test Harness Actually Looks Like

I've been thinking about this as two layers.

### Layer 1: Automated verification (CI)

This defines "correct." It runs on every PR. No human in the loop.

**A streaming mock server.** This is the foundation everything else builds on. An endpoint that replays canned SSE at realistic timing — same tokens, same chunk boundaries, same delays. Deterministic. No API key. You build this once and every other test depends on it. It lives on the server, not in the client — the client doesn't know it's talking to a mock.

**Browser interaction tests.** Playwright running against the real app with the mock server. Not unit tests — *behavior* tests:
- Send a message → verify it appears in the thread
- Receive a streaming response → verify scroll follows content
- Scroll up during streaming → verify scroll lock holds position
- Resize viewport mid-conversation → verify layout doesn't break
- Run on Chromium, WebKit, and Firefox. Run on 375px, 768px, and 1440px viewports.

These tests describe *intent*, not implementation. "Verify scroll follows content" doesn't care how the scroll handler works. It cares that the user sees the new content.

**Visual regression.** Playwright screenshots at key states — empty chat, single message, long thread, mid-stream, error state. Diff against baseline on every PR. This catches "the tests pass but the send button is under the keyboard on iOS." The class of bug that is invisible to unit tests and obvious to human eyes.

**Component-level tests.** Vitest for the logic that doesn't need a browser — state machine transitions, chunk parsing, message ordering. Fast, runs in Node, catches logic regressions in seconds.

### Layer 2: Dev-time tools (the agent's eyes)

This is how the agent validates its own work interactively, before pushing.

The agent needs to *see the app running*. Screenshots mid-development. DOM inspection. Console monitoring. The ability to say "I changed the scroll handler, let me check if it actually scrolls correctly on a 375px viewport."

We've been using MCP browser tools for this — the agent takes a screenshot, inspects the DOM, evaluates JavaScript in the page. It's not perfect. The agent still misses subtle visual issues. But it closes maybe 80% of the gap between "code looks right" and "code works right."

Neither layer alone is enough. Tests without visual feedback produce code that passes but feels wrong. Visual feedback without tests produces code that looks right but regresses next commit.

## The Economics Changed

The old argument against heavy frontend test suites was that maintenance cost more than the bugs they caught. Every UI change broke selectors, someone had to update them, nobody did, the suite rotted.

That argument assumed humans maintaining the tests. When the AI agent changes a component, it can update the tests in the same PR. The agent that breaks the test fixes the test. The maintenance tax that killed test suites isn't zero — but it's an order of magnitude lower than it was.

Self-healing selectors (tools like Stagehand layering AI over Playwright) push this further. Instead of `page.click('#send-btn')` — which breaks when someone renames the ID — you write `page.act('click the send button')` and the AI resolves the selector. The test describes intent. The implementation can change without the test breaking.

What hasn't changed: someone still has to define *what* to test. "Scroll follows content unless the user scrolls up" is a testable axiom. The agent can write the test and maintain it, but the human defines the contract.

## The Shift: Reviewing Iterations → Defining Constraints

Here's what actually changes when AI writes your frontend.

The old workflow: engineer writes code, reviewer reads it, finds problems, engineer fixes them, repeat. The human is in the loop at every iteration. This doesn't scale when the agent can produce a full component rewrite in minutes. (I wrote about the constraint-first model in [[Rapid Generative Prototyping: Design in the Post-Figma Era|Rapid Generative Prototyping]] — the question here is how you *verify* the output.)

The new workflow inverts the human's role. Instead of reviewing output, you define what "correct" means *before* the agent starts. The feedback loop becomes:

**Research → Physics → Constraints → Agent Loop → Human Signs Off**

**Research** is the deep work. Figure out how browsers actually behave — not how you think they behave, not what the docs suggest, but the mechanical truth. How scroll containers interact with flex layouts. How streaming DOM mutations affect animation. Where Safari diverges from Chrome. This isn't opinion. It's physics.

**Distill into constraints.** The research produces behavioral rules the agent can follow. Not "make it scroll nicely" but "scroll follows content during streaming unless the user scrolls up." Not "handle the input well" but "input auto-resizes to content with a max height of 40% viewport." Specific, testable, falsifiable.

**Build tests from the constraints.** Each constraint maps to a Playwright assertion. The E2E suite *is* the encoded constraint set.

**The agent loops against the constraints.** It writes code, runs the suite, sees failures, rewrites. The agent doesn't need taste or judgment about what "good" looks like — it has a boundary to stay within. The dev-time browser tools (MCP screenshots, DOM inspection) give it eyes for the visual stuff the tests can't capture. But the tests are the hard floor.

**The human reviews the final feel.** Not every diff. Not every iteration. The human defined what "correct" means upstream. Now the human checks whether the result *feels* right — the experiential layer that no test captures. This is a much smaller surface than reviewing every line of every PR.

The leverage is obvious: the human's time moves from the lowest-value activity (reading diffs) to the highest-value activity (defining what good means). The research and constraint-definition work compounds — once you've established the scroll physics, every future rewrite inherits them. The agent's iterations are cheap. The human's taste is expensive. Optimize accordingly.

## The Rewrite Pattern

We're about to rewrite our chat component from scratch. Here's the sequence:

1. Build the streaming mock server
2. Write Playwright tests against the *current* broken chat — capture every known bug as a failing test
3. Rewrite the component from scratch, grounded in behavioral constraints
4. Agent uses dev-time tools to iterate until tests pass on all viewports
5. Every future change runs the full suite

The rewrite produces a component that's probably 400 lines instead of 1,200 — because we're moving markdown rendering to the server (send HTML, not raw markdown the client has to parse), using a `<textarea>` instead of `contenteditable`, and getting the CSS layout right once instead of hacking around it.

But the test suite is the real product. The component will change. The constraints define what "working" means. They're the harness.

## How the Industry Is (Not) Handling This

Let me be honest about what I found researching this: the gap is bigger than I thought.

**Uber** just published something genuinely interesting — [uSpec](https://www.uber.com/blog/automate-design-specs/), an agentic system that uses Figma MCP to auto-generate component specs from their design system across seven implementation stacks. The entire system is structured markdown loaded into Cursor — TypeScript interfaces defined inside markdown files as output contracts, decision frameworks, validation checklists. No application code. The agent crawls the Figma component tree, reasons about it using the loaded frameworks, produces structured data matching the interface, then renders spec pages.

What makes uSpec relevant to the testing problem: they've built a machine-readable definition of what a component *is*. Anatomy, API surface, color tokens, spacing, screen reader behavior — all extracted into typed schemas. That's the piece most frontend testing lacks. You can't verify "correct" if you haven't defined it. uSpec's limitation is that it generates documentation, not tests — the verification is still human. But the architecture points somewhere: if your spec is structured data, the test can be generated from the spec.

The Figma Console MCP that uSpec builds on already has types for a *parity checker* — comparing design-to-code drift across visual properties, spacing, typography, tokens, component API, and accessibility. A `parityScore` and a list of `discrepancies[]`. The infrastructure for automated design-code verification exists in the type system. Nobody's wired it up as a CI gate yet. That's the gap.

**Figma MCP** is the enabling primitive that keeps showing up. When the agent can read the actual design file — not a screenshot but the component tree, the design tokens, the constraints — it can generate code against the real design rather than guessing. This is the difference between "AI looks at a screenshot and gets 70-80% there" and "AI reads the structural spec and gets 95% there." The last 5% is still the problem. But the 70→95% jump matters.

**Stagehand** (Browserbase) is the most interesting thing happening in browser testing. It layers AI over Playwright: you write `page.act('click the send button')` instead of `page.click('#send-btn')`. The AI resolves the selector. First run is slow (AI analyzes the page), subsequent runs use cached selectors, cache invalidates when the page changes. The hybrid pattern — Playwright for stable operations, Stagehand for dynamic parts — is the best answer I've seen to "how do you write tests that don't break every time the UI changes."

**What nobody has:** a way to test streaming frontend behavior specifically. "Message appears" is testable. "Message streams in token by token while scroll follows while markdown renders incrementally while the user is simultaneously scrolling up" — nobody has a framework for this. The streaming mock server + Playwright behavioral tests is, as far as I can tell, novel. Not because it's hard to build, but because the problem is new enough that nobody's standardized the solution.

## Who Decides "Good"?

This is the actual question underneath everything. Not "how do you test" but "how do you encode what good means."

For backend, it's relatively clear. The API contract says what the response looks like. The database schema says what valid data is. You can write assertions against concrete specifications. "Good" is falsifiable.

For frontend, "good" fractures into layers:

**Structural correctness** — does the right HTML exist in the DOM? This is testable. Vitest, Playwright, straightforward assertions.

**Behavioral correctness** — does the scroll follow content? Does the input resize? Does the error state render? This is testable but harder — you need a real browser, real viewports, real interaction sequences. Playwright handles this if you write the tests.

**Visual correctness** — does it *look* right? This is where it gets genuinely hard. A 2px misalignment passes every structural and behavioral test. A text overflow that clips on mobile but not desktop passes everything except human eyes. Screenshot diffing catches some of this, but not all — font rendering differences across OS, sub-pixel antialiasing, animation timing.

**Experiential correctness** — does it *feel* right? Is the scroll smooth? Does the streaming render feel natural or jittery? Is the input responsive? This is the 80→100% gap. No automated test can tell you whether a UI feels polished. An AI reviewer looking at a screenshot can catch some of it, but in my experience, unless you direct its attention at something very specific, it misses the subtle stuff.

The pattern that's emerging:

1. **Design tokens and component specs** define the visual contract (Uber's uSpec approach — the Figma file is the source of truth, the spec is structured data, not a screenshot)
2. **Behavioral axioms** define interaction contracts ("scroll follows content unless user scrolls up" — testable with Playwright)
3. **Structural tests** verify the DOM (Vitest, fast, in CI)
4. **Browser tests** verify behavior across surfaces (Playwright + Stagehand, slower, in CI)
5. **Visual regression** catches pixel-level drift (screenshot baselines, in CI)
6. **Human review** catches everything else — the feel, the polish, the "this technically works but feels wrong"

The insight from uSpec's architecture: if the spec is structured data — TypeScript interfaces, token references, behavioral rules — then the test can be *generated from the spec*. The contract IS the test specification. Most frontend testing struggles because there's no authoritative definition of "correct" to test against. Backend has the API contract and the database schema. Frontend has... a Figma file that someone eyeballs. uSpec is closing that gap for documentation. The same pattern closes it for verification.

An AI code reviewer is probably enough for layers 1-3. For layers 4-5, you need browser automation. For layer 6, you need a human. The question is how thin you can make layer 6 by investing in layers 1-5.

## The Uncomfortable Conclusion

The industry is shipping AI-generated frontends faster than it's building the infrastructure to verify them. Nobody is publicly sharing how they test the frontend output at the level of "does this chat scroll correctly on an iPhone SE."

The tools that win the next two years aren't better code generators. They're better code verifiers. The harness, not the engine.

And honestly — this isn't new. "Test the hard stuff first" has always been the right advice. We just have a new category of hard stuff (stateful, streaming, visual), a new category of developer that can't see what it ships, and a new urgency because the speed of generation now vastly outpaces the speed of verification.

The frontend testing gap is where quality goes to die. And nobody's talking about it because the code compiles and the backend tests pass.