Testing Interview Questions and Answers
Jest and Vitest, React Testing Library, mocks and MSW, Playwright and Cypress, the test pyramid: what, how and at which level to test.
228 questions for Testing interviews with answers and explanations - Junior, Middle and Senior levels. Sample questions, online quizzes and coding tasks.
- Jest
- Vitest
- Testing Library
- Mocks
- Playwright
- Cypress
Questions by level
Junior
Core concepts and syntax · 50 questions
Middle
Practice, nuances and optimization · 50 questions
Senior
Architecture, internals, edge cases · 50 questions
Sample questions
A few questions from each level with the correct answer and an explanation.
Testing · Junior
- What is the main goal of automated tests?
Correct answer: To give confidence that the code works and keeps working after changes
Tests can show the presence of bugs, not their absence. Their value is fast feedback and safe refactoring: if behaviour breaks, a test fails before users notice.
- What does a unit test check?
Correct answer: A small isolated piece of code - a function, a hook or a component - on its own
Unit tests are fast and pinpoint the failing place. Their limit: they don't show whether the pieces work together.
- What does an integration test check?
Correct answer: That several units work correctly together, e.g. a form with validation and an API call
In frontend, an integration test usually renders a feature (several components, state, router) and mocks only the network boundary.
- What is an end-to-end (E2E) test?
Correct answer: A test that drives the real app in a browser the way a user would, through UI, API and database
E2E tests give the most confidence but are slower and more fragile. Typical tools: Playwright and Cypress.
Testing · Middle
- What is the difference between
findBy…andwaitFor?Correct answer:
findBywaits for one element to appear;waitForretries any callback until it stops throwingfindByRole(...)is literallywaitFor(() => getByRole(...)). UsefindByto wait for an element andwaitForfor other assertions. - How do you wait for a loading spinner to disappear?
Correct answer:
await waitForElementToBeRemoved(() => screen.queryByRole("progressbar"))The helper requires the element to be present at the start, then waits until the query returns
null. - What does the warning “An update to Component inside a test was not wrapped in act(...)” usually mean?
Correct answer: State changed after the test stopped waiting - e.g. a request resolved after the last assertion
RTL already wraps
renderand events inact. The fix is usually to wait for the final UI state withfindBy/waitFor, not to addactmanually. - How do you test a debounced search input?
Correct answer: Use fake timers, type, advance time by the debounce delay and check the request/result
Fake timers make the test fast and deterministic. Real waits slow the suite and still race.
Testing · Senior
- How do you decide where to place a test in the pyramid/trophy?
Correct answer: At the lowest level that can still catch the failure you care about with enough confidence
If a bug can be caught by a unit or integration test, a duplicate E2E test only adds cost. E2E is for what lower levels can't see: real wiring, deployment, third-party integrations.
- Why does Google's “Just Say No to More End-to-End Tests” argue against relying on E2E?
Correct answer: E2E failures are slow to arrive, hard to isolate and often flaky, so the feedback loop is weak
Good tests are fast, reliable and isolate failures. A suite of mostly E2E tests fails on all three.
- What is the “testing honeycomb” and where is it used?
Correct answer: A shape for microservices: mostly integration tests of a service through its API, few implementation-detail unit tests and few integrated tests
Spotify's model fits services whose complexity lies in interactions rather than internal logic.
- What are Google's “test sizes” (small, medium, large) based on?
Correct answer: Resources a test may use: small - one process, no I/O; medium - one machine, localhost; large - anything, including remote systems
Sizes describe constraints that make tests fast and deterministic, independent of the “unit/integration” naming debate.
Combined quizzes with this topic
Questions from several topics at once - just like an interview for a specific role.
Coding tasks
Write your solution right in the browser, and tests check it instantly. Interview classics: debounce, throttle, deepClone, Promise.all, EventEmitter, an LRU cache and more.
Open tasks →