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