Chapter 4 · Testing
Interview drill
8 questions from this chapter. Answer each one out loud first, then open it to compare.
-
4.1"What's your testing strategy for a large frontend?"
- Name the shape and the ratio, then justify it by CI time and debugging cost, not by dogma.
- Cover money paths with E2E, everything else lower; add visual and a11y checks as separate gates.
- State the flake policy — quarantine within a day — because that's what keeps a suite trusted.
-
4.2"Where's the line between a unit and an integration test?"
- It's the mocking boundary, not the file count — one component with a mocked child is a unit test.
- I default to mocking only the network (MSW), so the real render, state, and event path stay under test.
- That makes tests survive refactors, which is the property that decides whether a suite lasts.
-
4.3"Your E2E suite is flaky. How do you fix it?"
- Measure first: track per-test failure rate and quarantine anything under 99% within a day.
- Attack the structural causes — shared data, real third parties,
sleep-based waits, animation timing. - Then shrink the suite; most flaky E2E suites are covering things that belong two layers down.
-
4.4"How do you A/B test without hurting performance?"
- Decide at the edge so the variant ships in the HTML — no flicker, no extra round trip, no layout shift.
- Keep the payload as one small config object, not two bundles; lazy-load only genuinely divergent code.
- Add latency and error rate as guardrail metrics, so a winning variant that slows the page still loses.
-
4.5"How do you stop performance regressing over time?"
- Make it a gate, not a goal: budgets fail CI so no regression merges silently.
- Cheap deterministic checks (bundle size) on every PR, full Lighthouse on main, RUM alerting in production.
- Track p75 on real devices — averages hide exactly the users who churn.
-
4.6"Do you practise TDD?"
- For logic-heavy code and for every bug fix, yes — a bug without a failing test first has no proof it's fixed.
- For visual and exploratory UI work I build first and test the settled behaviour, because the interface is still moving.
- The durable benefit isn't coverage, it's that untestable code is usually badly designed code, and TDD surfaces that immediately.
-
4.7"How do you test security in a frontend pipeline?"
- Layer it: secrets at commit, dependencies and SAST on PR, DAST on staging, header assertions as ordinary tests.
- Gate only on reachable high severity, or the team learns to bypass the gate entirely.
- Automation finds known patterns; business-logic flaws — like an IDOR on an order id — still need a human.
-
4.8"How do you test a component that fetches data?"
- MSW intercepts at the network layer, so the real fetch, real serialization, and real error branches all run.
findBy*for the resolved state,queryBy*to assert the loading state is gone — neversleep.- Cover all four states — loading, empty, error, success — since the last three are where production bugs actually live.