Challenge - 5 Problems
Nested Assertion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ assertion
intermediate2:00remaining
Check nested property value in JSON response
Given the following JSON response, which Postman test assertion correctly verifies that the user's city is 'New York'?
Postman
{
"user": {
"id": 123,
"name": "Alice",
"address": {
"city": "New York",
"zip": "10001"
}
}
}Attempts:
2 left
💡 Hint
Remember to follow the exact path to the nested property in the JSON structure.
✗ Incorrect
The city property is nested inside user.address. Option B correctly accesses user.address.city. Options A and C miss the correct nesting, and D checks the zip code instead of city.
❓ assertion
intermediate2:00remaining
Verify array length inside nested object
You receive this JSON response. Which assertion correctly checks that the user has exactly 3 phone numbers?
Postman
{
"user": {
"phones": ["123-4567", "234-5678", "345-6789"]
}
}Attempts:
2 left
💡 Hint
Use the correct Chai assertion to check array length.
✗ Incorrect
Option A uses the proper Chai assertion 'to.have.lengthOf' on the array. Option A compares length property with eql(3) which works but is less idiomatic. Option A accesses wrong path. Option A compares array to number, which is invalid.
❓ Predict Output
advanced1:30remaining
Output of nested object assertion with missing property
What will be the result of this Postman test if the JSON response is missing the 'email' property inside 'user'?
Postman
pm.test('User email exists', () => {
pm.expect(pm.response.json().user.email).to.exist;
});Attempts:
2 left
💡 Hint
Check how Chai's 'to.exist' behaves with undefined values.
✗ Incorrect
'to.exist' assertion fails if the value is undefined or null. Accessing a missing property returns undefined, so the test fails with an assertion error. It does not throw a runtime error.
🔧 Debug
advanced2:00remaining
Identify error in nested object assertion code
This Postman test is intended to check if the user's first hobby is 'reading'. What is the error in the code?
Postman
pm.test('First hobby is reading', () => { pm.expect(pm.response.json().user.hobbies[0] === 'reading'); });
Attempts:
2 left
💡 Hint
pm.expect needs a matcher method to assert values.
✗ Incorrect
pm.expect expects a value followed by a matcher like 'to.eql'. Writing pm.expect(condition) without a matcher does not assert anything and the test passes regardless of condition.
❓ framework
expert3:00remaining
Best practice for nested object assertions in Postman tests
Which approach is best to safely assert a deeply nested property 'user.profile.contact.email' exists and equals 'test@example.com' without causing runtime errors if intermediate properties are missing?
Attempts:
2 left
💡 Hint
Consider safe access methods to avoid runtime errors in nested assertions.
✗ Incorrect
Option C uses lodash's _.get method to safely access nested properties without runtime errors if any intermediate property is missing. Option C throws error if any property is missing. Option C uses optional chaining but Postman sandbox may not support it fully. Option C is verbose and repeats calls.