← All topics

Testing Middle interview questions and answers

75 questions for a Testing (Middle) interview - with correct answers, explanations and links to the docs.

Take this quiz
  1. 1.What is the difference between findBy… and waitFor?
  2. 2.What is wrong with this waitFor?
  3. 3.How do you wait for a loading spinner to disappear?
  4. 4.What does the warning “An update to Component inside a test was not wrapped in act(...)” usually mean?
  5. 5.What is wrong with waiting like this?
  6. 6.How do you use fake timers together with user-event v14?
  7. 7.How do you test a debounced search input?
  8. 8.What does vi.runAllTimers() do differently from vi.advanceTimersByTime(1000)?
  9. 9.How do you fix the current date in a test?
  10. 10.Why can vi.mock("./api") be written below the imports and still work?
  11. 11.Why does this mock factory fail?
  12. 12.How do you mock only one export of a module and keep the rest real?
  13. 13.What is the difference between mockClear, mockReset and mockRestore?
  14. 14.What does mockImplementationOnce allow?
  15. 15.Where do manual mocks for a node module live in Jest?
  16. 16.Why does vi.spyOn(module, "fn") often fail to affect calls inside the same ES module?
  17. 17.Why is MSW often preferred over mocking fetch/axios directly?
  18. 18.How do you set up MSW for tests in Node.js?
  19. 19.How do you make one test get a 500 error from an endpoint with MSW?
  20. 20.How do you check what a component sent to the API when using MSW?
  21. 21.How do you render a component that needs providers (router, store, query client)?
  22. 22.How do you search inside one part of the page, e.g. one table row?
  23. 23.What does renderHook return?
  24. 24.How do you test that a component reacts to new props?
  25. 25.How do you find a heading of a specific level?
  26. 26.Why can getByRole miss an element that is in the DOM?
  27. 27.How do you test a component that reads from a Redux store?
  28. 28.How do you test a component that uses TanStack Query?
  29. 29.How do you test a component that depends on the current route (React Router)?
  30. 30.How do you check that a checkbox is checked?
  31. 31.What does toHaveAccessibleName check?
  32. 32.How can you find the best query for an element quickly?
  33. 33.What is wrong with calling cleanup manually in afterEach?
  34. 34.Why is getByRole slower than getByText, and what to do about it?
  35. 35.What are the downsides of large component snapshots?
  36. 36.What is toMatchInlineSnapshot?
  37. 37.What does branch coverage measure that line coverage misses?
  38. 38.What does a coverage threshold in config do?
  39. 39.Which coverage providers does Vitest support?
  40. 40.What is a setup file (setupFiles in Vitest, setupFilesAfterEnv in Jest) used for?
  41. 41.What does globals: true in Vitest config do?
  42. 42.Why do Jest and Vitest isolate test files by default?
  43. 43.What is a Playwright locator?
  44. 44.What does strictness mean for Playwright locators?
  45. 45.How do you narrow a list item locator to the one that contains a text?
  46. 46.Why is expect(await locator.isVisible()).toBe(true) worse than await expect(locator).toBeVisible()?
  47. 47.How do you mock an API response in Playwright?
  48. 48.How do you avoid logging in through the UI in every Playwright test?
  49. 49.How does Playwright isolate tests from each other?
  50. 50.What is the Playwright trace viewer useful for?
  51. 51.What are Playwright fixtures?
  52. 52.How do you start the app automatically before Playwright tests?
  53. 53.What does expect.poll do in Playwright?
  54. 54.Why is page.waitForTimeout(3000) discouraged?
  55. 55.What does test.describe.configure({ mode: "serial" }) mean, and why use it rarely?
  56. 56.Why can't you write const text = cy.get("h1").text() in Cypress?
  57. 57.What gets retried in a Cypress chain like cy.get(".list li").should("have.length", 3)?
  58. 58.How do you wait for a specific request in Cypress?
  59. 59.What does cy.session() do?
  60. 60.What is a key architectural difference between Cypress and Playwright?
  61. 61.Which Cypress practice is an anti-pattern?
  62. 62.Why are integration tests in the frontend often the best value?
  63. 63.Which test type best fits “checkout works with the real backend and payment sandbox”?
  64. 64.What does a contract test check?
  65. 65.What should you do with a flaky test you can't fix right away?
  66. 66.What are the common causes of flaky UI tests?
  67. 67.What does “Given–When–Then” correspond to in a test?
  68. 68.Why is deep nesting of describe blocks with shared let variables problematic?
  69. 69.What should a component test NOT assert?
  70. 70.How can automated accessibility checks be added to component tests?
  71. 71.What is component testing in Playwright or Cypress?
  72. 72.What is Vitest Browser Mode?
  73. 73.What do asymmetric matchers like expect.objectContaining give you?
  74. 74.How do you check that “Submit” is disabled until the form is valid?
  75. 75.How are retries usually configured in Playwright?