Test behavior at the level a user experiences it. Component tests that render a component and interact through visible text and roles catch the most bugs per unit of effort; pure unit tests suit logic like formatting and reducers; a small set of end to end tests covers the critical journeys such as signup and checkout. Avoid tests that assert on implementation details, since they break on every refactor without catching real regressions.
Why interviewers ask this
The interviewer wants to see judgment about cost and value rather than a testing pyramid recital. Frontend tests are famously brittle, so they are listening for how you avoid coupling to markup structure, how you handle network calls, and whether you have opinions about snapshot tests. It also tells them whether you would leave a suite the next person trusts.
How to structure your answer
- State the principle: test what the user does, not how it is built.
- Assign a test type to each kind of code.
- Explain how you handle network and time.
- Name a practice you avoid and why.
Example answer
My rule is that a test should fail when the behavior breaks and survive a refactor. So most of my tests render a component and drive it the way a user would, finding elements by role and label rather than test ids or class names, which means the accessibility of the component gets exercised too. Pure logic like a date formatter or a reducer gets plain unit tests, because they are cheap and fast. Then a small end to end suite in Playwright over the journeys that cost money if they break: sign up, log in, checkout. Network calls get intercepted at the boundary with a mock server rather than by mocking the fetch function, so the test covers my real request code. What I avoid is large snapshot tests, because nobody reviews a two hundred line diff and they get accepted blindly, and anything asserting on internal state. The other thing I insist on is that end to end tests run against a seeded environment, since flaky shared data is what makes teams start ignoring red builds.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- How do you keep end to end tests from becoming flaky?
- What is your approach to testing a component that fetches its own data?
- Where do visual regression tests fit for you?
Related frontend developer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions