Given the following Postman test script that inspects the response body, what will be the test result?
pm.test("Check user name", function () { var jsonData = pm.response.json(); pm.expect(jsonData.user.name).to.eql("Alice"); });
Look at the assertion method to.eql and what it checks.
The test uses pm.expect(...).to.eql(...) which checks for exact equality. The test passes only if jsonData.user.name is exactly 'Alice'.
Choose the Postman test assertion that correctly verifies the response body JSON has a key status with value success.
Remember that pm.response.json() parses the response body as JSON.
Option A correctly parses the response body as JSON and asserts the status key equals 'success'. Option A is invalid because pm.response.body is a string, not an object. Option A uses to.contain which is for strings or arrays, not exact equality. Option A is invalid because pm.response.body is a string and does not have have.property.
Consider this test script:
pm.test("Check user id", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.user.id).to.be.a('number');
});The test fails with the error above. What is the most likely cause?
Check what happens if you try to access a property of undefined.
The error means jsonData.user is undefined, so trying to access id on it causes a TypeError. This happens if the response JSON lacks the 'user' key.
In Postman, you want to verify the response body JSON has an array called items and it contains at least one element. Which test assertion is correct?
Check how to assert type and length in Postman using Chai assertions.
Option B correctly asserts that items is an array and its length is greater than 0. Option B only checks length but not type. Option B uses incorrect chaining. Option B uses invalid chaining syntax.
You want to write a Postman test that checks if response.data.user.profile.email exists and is a non-empty string, but the response may not always have all nested keys. Which approach is safest to avoid runtime errors?
Think about how to safely access nested properties without causing errors.
Option A uses explicit checks for each nested key before accessing email, preventing runtime errors if any key is missing. Option A will throw an error if any key is missing. Option A uses optional chaining which is not supported in Postman test scripts. Option A assumes email exists and uses fallback but will throw if intermediate keys are missing.