Complete the code to check if the response body contains the expected status.
pm.test("Status is OK", function () { pm.response.to.have.status([1]); });
The HTTP status code 200 means the request was successful. This assertion checks that the response status is 200.
Complete the code to parse the JSON response body.
let jsonData = pm.response.json(); pm.test("Check user name", function () { pm.expect(jsonData.name).to.eql([1]); });
The expected value must be a string literal with double quotes in JavaScript. So "John" is correct.
Fix the error in the assertion to check if the response body has a property 'success' set to true.
pm.test("Success is true", function () { pm.expect(pm.response.json().success).to.be.[1]; });
The assertion to check a boolean true value uses to.be.true.
Fill both blanks to check if the response JSON has a property 'data' and that it is an array.
pm.test("Data is an array", function () { let jsonData = pm.response.json(); pm.expect(jsonData).to.have.property([1]); pm.expect(Array.isArray(jsonData.[2])).to.be.true; });
The property name must be a string in quotes for the first assertion. For accessing the property, use the variable name without quotes.
Fill all three blanks to test that the response JSON has a 'user' object with a 'role' property equal to 'admin'.
pm.test("User role is admin", function () { let jsonData = pm.response.json(); pm.expect(jsonData).to.have.property([1]); pm.expect(jsonData.[2]).to.have.property([3]); pm.expect(jsonData.user.role).to.eql("admin"); });
The first property name must be a string in quotes for have.property(). The second property is accessed as a variable name without quotes. The third property name is a string in quotes for have.property().