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 });- 1Read the request from the HTML report later
- 2Wait for the request and check
postDataJSON() - 3Check the server logs after the test finishes
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.