Testing Interview Questions
Frontend testing interview map — Testing Library, pyramid tradeoffs, mocks, a11y tests, and how to talk test strategy.
intermediate3 min read
- interview
- testing-interview
Testing interviews rarely want 90% coverage brags. They want risk-based strategy: what you test, at which layer, and how you avoid brittle suites.
What interviewers score
- Pyramid judgment — unit / integration / e2e balance
- User-centric queries — Testing Library philosophy
- Async & mocks — network without flaking
- What not to test — implementation details
- CI reality — flake control, a11y gates
Pyramid & tradeoffs
| Layer | Best for | Cost | Learn |
|---|---|---|---|
| Unit | Pure logic, reducers, parsers | Low | Unit testing pure logic |
| Component / integration | User flows in JSDOM | Medium | Integration testing UI · Testing Library |
| E2E | Critical money paths | High | E2E tradeoffs · Playwright vs Cypress |
Overview: Testing pyramid for frontend.
Out loud: “Many tests around pure pricing logic; RTL for form submit; one Playwright smoke for checkout.”
Testing Library core
| Topic | Can you… | Learn |
|---|---|---|
| Query priority | role/label over test ids | Queries priority |
| user-event | Prefer over fireEvent | user-event vs fireEvent |
| Async | findBy, waitFor |
|
| test ids | Last resort | test ids |
// Strong: role + name
await user.click(screen.getByRole("button", { name: /save/i }));
expect(await screen.findByText(/saved/i)).toBeInTheDocument();
Network mocking
| Approach | When | Learn |
|---|---|---|
| Mock fetch | Small unit of client | Mocking fetch |
| MSW | App-level integration | MSW |
| Contract tests | Multi-team APIs | Contract testing |
Flakes & timers
| Topic | Can you… | Learn |
|---|---|---|
| Flake causes | races, shared state, time | Flaky tests |
| Fake timers | debounce/throttle tests | Fake timers |
| Snapshots | rare, intentional | Snapshot testing |
Coverage & CI
| Topic | Can you… | Learn |
|---|---|---|
| Coverage pitfalls | 100% ≠ quality | Coverage pitfalls |
| A11y in CI | axe checks + limits | A11y testing CI · axe limits |
| Visual regression | design systems | Visual regression |
| Storybook | component states | Component testing Storybook |
Classic questions
| Question | Strong direction |
|---|---|
| Unit vs integration? | Isolation speed vs confidence in wiring |
| Why not test internals? | Refactors break tests; users don’t call hooks directly |
| How test hooks? | Via component or renderHook carefully |
| E2E count? | Few critical paths; rest lower pyramid |
| How handle auth in e2e? | Test user / storage state / stub IdP |
| Snapshot everything? | No — noise and rubber-stamp reviews |
Strategy prompt (use structure)
“Design a test plan for an autocomplete.”
- Unit: filter ranking function
- RTL: type query, see options, keyboard select
- MSW: slow/error network states
- E2E: optional one path if search is revenue-critical
- A11y: axe + manual keyboard
Practice UI: Autocomplete.
Footguns
- Testing Redux connected guts instead of behavior
- Snapshot of entire page HTML
- Sleeping 5s instead of waiting for condition
- Mocking so much nothing is real
- Zero tests on pure money logic
Related on this site
- Testing Library
- Testing pyramid
- Testing craft roadmap
- React interview
- Machine coding framework
- Interview hub
Further reading
Good testing answers sound like risk management, not framework fandom.