11. Network Interception with page.route()

Mocking API Calls with page.route()

await page.route("**/api/cart", async (route) => {
  await route.fulfill({
    status: 200,
    contentType: "application/json",
    body: JSON.stringify({ count: 5 }),
  });
});

Task

  • Use `route.fulfill` to return status 200 and mocked cart count.
💡Common doubts
Did you like the problem?
Lesson 11 of 12
TypeScript
Loading code editor…
Next