What testing strategy would you use for a frontend application?
What the interviewer wants to hear
- Unit tests for pure logic and utilities
- Component tests that test behaviour like a user would
- End-to-end tests for critical user journeys
- Mock network at the boundary, for example with MSW
- Run tests in CI, keep them fast and not flaky
- Add accessibility and visual checks where useful
Model answer
I use a mix, sometimes called the testing trophy. Pure logic, like formatting and validation, gets fast unit tests with Vitest. Most of the value comes from component and integration tests with React Testing Library, where I render a component and interact with it like a user, finding elements by role and label rather than class names. I mock the network at the boundary with MSW so tests use realistic responses. For the few critical journeys, like sign-up, login and checkout, I write end-to-end tests with Playwright against a real build. Everything runs in CI on each pull request. I keep tests independent and avoid fixed waits to prevent flakiness, and I add automated accessibility checks like axe on key pages.
Can you answer it under time pressure?
Take a timed medium round and get scored on every answer.
More medium Frontend Developer questions
- Explain the JavaScript event loop, including microtasks and macrotasks.
- How do you decide where to keep state in a React app: local state, context, a store, or a server-cache library?
- A page has a poor LCP score. How would you investigate and fix it?
- Explain client-side rendering, server-side rendering and static site generation. When would you use each?
- What happens between typing a URL in the browser and seeing the page rendered? Focus on the frontend side.
- A React screen feels slow. How do you find and reduce unnecessary re-renders?
- How do you handle loading, error and empty states when a screen fetches data from an API?
- How do you use TypeScript effectively in a React codebase?
- How would you handle user authentication and tokens in a single-page app or Next.js frontend?