Technical Mid Level

How do you test React components? What is your approach to unit tests versus integration tests for UI code?

Quick Tip

Emphasise user-centric testing: "I use React Testing Library with getByRole queries, test what the user sees and does, and mock API calls with MSW to test realistic flows."

What good answers include

Best practice: test behaviour, not implementation. Use React Testing Library to render components and interact with them as a user would. Unit test custom hooks in isolation. Integration test key user flows. Avoid testing implementation details like internal state or DOM structure. Strong candidates mention accessibility queries (getByRole, getByLabelText) and mock APIs at the network level (MSW).

What interviewers are looking for

Tests professional frontend practices. Candidates who test implementation details (checking state values, counting renders) are writing brittle tests. Those who use RTL idiomatically and focus on behaviour are strong.

← All React questions