Next.js Discord

Discord Forum

Mocking api routes with playwright.

Unanswered
starlord posted this in #help-forum
Open in Discord
What is the recommended way to mock api routes response in a playwright test where the api routes are being called by react query in server and client components?

1 Reply

I tried using the official playwright guide to mock requests like this, but it doesn't do anything
await context.route("http://localhost:3000/api/permissions", (route) => { route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify(mockPermissions), }); });