Playwright · Middle · Question 75 of 75

How do you test that a request is sent with the right body?

const request = page.waitForRequest("**/api/feedback");
await page.getByRole("button", { name: "Send" }).click();
expect((await request).postDataJSON()).toEqual({ rating: 5 });
Show the answer

Correct answer: Wait for the request and check postDataJSON()

Explanation

Checking what the frontend sends catches bugs that a mocked backend would otherwise hide.

Further reading

Problem with a question

Playwright · Middle · question 75

Test yourself

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

Take this quiz