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" }] }),
);

Explanation

route.continue() lets the request through (optionally modified), route.abort() simulates a network failure.

Further reading

Problem with a question

Testing · Middle · question 47

Test yourself

Take the Testing · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz