Frontend Engineer
How do you test a component that fetches data and shows loading and error states?
What the interviewer is looking for
- This question tests frontend testing. Tests user-visible behaviour, mocks network calls sensibly, and balances component tests with a few end to end tests.
- Strong answers: Mocking the network layer, testing what the user sees rather than internals, covering loading, success, empty and error states, and avoiding flaky timing.
- Likely follow-up: When would you add an end to end test on top of that?
Another way it may be asked: You've built a user profile card that loads from an API. How would you write tests that check it behaves properly in every case?
A structure to follow: Answer, explain, example, limits
- Step 1
Answer
Give your direct answer in the first sentence so the interviewer knows where you are going.
- Step 2
Explain
Say how it works or why you would do it that way, in plain words before jargon.
- Step 3
Example
Anchor it in something you have actually done or seen, with the detail that shows hands-on experience.
- Step 4
Limits
Say when your approach would not be the right one. It shows judgement.
This is guidance on shape, not a script. Use your own real experience and facts; never invent details to fill a gap. See the STAR guide and answer frameworks.
Common slips
- Reciting a definition without showing you have applied it.
- Using terms you cannot explain if asked a level deeper.
- Claiming experience beyond what you can discuss in detail.
How to practise it
Say the answer in 90 seconds, then answer the follow-up as if it were a new question.
Related questions
- How would you build a layout that looks good on both a phone and a wide desktop screen? Talk me through your approach.
- Can you explain what happens when you await a promise in JavaScript, and how you handle errors from it?
- What are some simple things you do to make sure a form can be used by someone on a screen reader or only a keyboard?
- How do you decide where a piece of state should live in a React or similar app, and when do you reach for a global store?
- A product page feels slow to load on mobile. How would you find out why, and what would you try first?