Complete the code to assert the response status is 200.
pm.test("Status code is 200", function () { pm.response.to.have.status([1]); });
The status code 200 means the request was successful. We use pm.response.to.have.status(200) to check this.
Complete the code to assert the JSON response has a property 'userId' equal to 1.
pm.test("User ID is 1", function () { var jsonData = pm.response.json(); pm.expect(jsonData.[1]).to.eql(1); });
The JSON response property is named userId. We access it as jsonData.userId to check its value.
Fix the error in the code to assert the response time is less than 500 ms.
pm.test("Response time is less than 500ms", function () { pm.expect(pm.response.[1]).to.be.below(500); });
The correct property for response time in Postman is pm.response.responseTime. Using this allows the assertion to check the response time correctly.
Fill both blanks to assert the JSON response array length is greater than 3.
pm.test("Array length is greater than 3", function () { var jsonData = pm.response.json(); pm.expect(jsonData.[1].[2]).to.be.above(3); });
The JSON response has an array property named items. To get its length, we use items.length. Then we check if it is above 3.
Fill all three blanks to assert the response header 'Content-Type' includes 'json'.
pm.test("Content-Type header includes json", function () { var contentType = pm.response.headers.get('[1]'); pm.expect(contentType.[2]('[3]')).to.be.true; });
We get the header named Content-Type (case sensitive). Then we check if it includes the string json using the includes method.