Complete the code to check if 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. This assertion checks that the response status is exactly 200.
Complete the code to assert that the response body contains the string 'success'.
pm.test("Body contains success", function () { pm.expect(pm.response.text()).to.include([1]); });
This assertion checks if the response body text includes the word 'success'. It helps verify that the API returned a successful message.
Fix the error in the code to correctly assert that the JSON response has a property 'id'.
pm.test("Response has id", function () { const jsonData = pm.response.json(); pm.expect(jsonData).to.have.property([1]); });
The property name must be a string, so it needs quotes. Using "id" correctly checks if the JSON object has that property.
Fill both blanks to assert that the response JSON has a property 'name' and its value equals 'John'.
pm.test("Name is John", function () { const jsonData = pm.response.json(); pm.expect(jsonData).to.have.property([1], [2]); });
The property name must be a string with quotes, and the expected value must also be a string with quotes. Both double and single quotes are acceptable, but must be consistent.
Fill all three blanks to assert that the response JSON array 'users' has length greater than 0 and the first user's 'active' property is true.
pm.test("Users array is not empty and first user is active", function () { const jsonData = pm.response.json(); pm.expect(jsonData.[1]).to.be.an('array').that.has.length.[2](0); pm.expect(jsonData.users[0].[3]).to.be.true; });
The 'users' property is the array. The assertion 'above(0)' checks the array length is greater than zero. The 'active' property of the first user is checked to be true.