Challenge - 5 Problems
Response Body Assertion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ assertion
intermediate2:00remaining
Check if response JSON contains a specific key with expected value
Given a JSON response body, which Postman test script correctly asserts that the key
status has the value success?Postman
pm.test('Status is success', function () {
// Write assertion here
});Attempts:
2 left
💡 Hint
Use the correct assertion method to compare values exactly.
✗ Incorrect
Option A uses to.eql() which checks deep equality and matches the string 'success'. Other options either use wrong assertion methods or compare to wrong types.
❓ assertion
intermediate2:00remaining
Verify response body contains a non-empty array
Which Postman test script correctly asserts that the response JSON has a key
items which is an array with at least one element?Postman
pm.test('Items array is not empty', function () {
// Write assertion here
});Attempts:
2 left
💡 Hint
Use chaining to check type and emptiness.
✗ Incorrect
Option A correctly asserts that items is an array and is not empty using Chai's BDD style. Other options have syntax errors or incorrect chaining.
❓ Predict Output
advanced2:00remaining
Output of response body assertion with nested JSON
What will be the result of this Postman test script if the response body is
{"user":{"id":123,"active":true}}?Postman
pm.test('User is active', function () {
pm.expect(pm.response.json().user.active).to.be.false;
});Attempts:
2 left
💡 Hint
Check the actual value of the
active key and the assertion used.✗ Incorrect
The assertion expects active to be false but the response has it as true, so the test fails with an assertion error.
🔧 Debug
advanced2:00remaining
Identify the error in response body assertion script
What is wrong with this Postman test script if the response body is
{"data":{"count":5}}?
pm.test('Count is 5', function () {
pm.expect(pm.response.json().count).to.eql(5);
});Attempts:
2 left
💡 Hint
Check the JSON path used to access the count key.
✗ Incorrect
The script tries to access count at the root level but it is inside the data object, so pm.response.json().count is undefined causing the assertion to fail.
🧠 Conceptual
expert3:00remaining
Best practice for asserting optional keys in response body
In Postman tests, what is the best way to assert that an optional key
message in the response body is either absent or a non-empty string if present?Attempts:
2 left
💡 Hint
Think about how to handle keys that may or may not be present.
✗ Incorrect
Option C is best practice because it handles both cases gracefully: if the key exists, it validates the value; if not, it does not fail the test unnecessarily.