Testing · Middle · Question 47 of 75
How do you mock an API response in Playwright?
await page.route("**/api/products", (route) =>
route.fulfill({ json: [{ id: 1, name: "Cup" }] }),
);- ✓Correct answer: With
page.routeandroute.fulfill - 2With
vi.mock - 3With
cy.intercept
Explanation
route.continue() lets the request through (optionally modified), route.abort() simulates a network failure.