Playwright · Junior · Question 61 of 75

What does this API test check?

const res = await request.get("/api/users/1");
expect(res.ok()).toBeTruthy();
expect(await res.json()).toMatchObject({ id: 1 });
Show the answer

Correct answer: Status is 2xx and the body contains id: 1

Explanation

ok() is true for 200-299 responses. toMatchObject checks a subset of fields, ignoring others.

Further reading

Problem with a question

Playwright · Junior · question 61

Test yourself

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

Take this quiz