Test Overview
This test sends a GET request to a sample API endpoint and uses the Chai assertion library to verify that the response status is 200 and the response body contains a specific property.
This test sends a GET request to a sample API endpoint and uses the Chai assertion library to verify that the response status is 200 and the response body contains a specific property.
pm.test("Status code is 200", function () { pm.response.to.have.status(200); }); pm.test("Response has userId property", function () { const jsonData = pm.response.json(); pm.expect(jsonData).to.have.property('userId'); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Send GET request to https://jsonplaceholder.typicode.com/posts/1 | Request sent, waiting for response | — | PASS |
| 2 | Check response status code using pm.response.to.have.status(200) | Response received with status 200 | Verify status code is 200 | PASS |
| 3 | Parse response JSON and check if it has property 'userId' using pm.expect | Response body parsed as JSON: { userId: 1, id: 1, title: "...", body: "..." } | Verify response JSON has property 'userId' | PASS |
pm.response.pm.expect(pm.response.code).to.equal(200);.pm.test('Check response body', () => {
pm.expect(pm.response.text()).to.include('success');
});'Operation was successful'?pm.test('Status is 404', () => {
pm.expect(pm.response.status).to.equal(404);
});pm.response.code, not pm.response.status.to.equal syntax is correct and pm.test is used properly.userId with a value greater than 100. Which code snippet correctly uses Chai assertions to do this?pm.response.json() to get the response as an object.jsonData.userId is greater than 100 with to.be.above(100).Pass the test and this pattern moves unknown