Challenge - 5 Problems
Response Array Assertion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ assertion
intermediate2:00remaining
Check if response array contains an object with a specific property value
Given a JSON response body containing an array of user objects, which Postman test script correctly asserts that at least one user has the username 'alice'?
Postman
pm.test('Response has user with username alice', () => {
const jsonData = pm.response.json();
// Write assertion here
});Attempts:
2 left
💡 Hint
Use an array method that returns true if any element matches the condition.
✗ Incorrect
Option B uses the 'some' method to check if any user object has username 'alice', then asserts it is true. Option B incorrectly compares an object to true. Option B checks for zero matches, which is opposite of the goal. Option B tries to check if the array includes a string directly, which won't work for objects.
❓ assertion
intermediate2:00remaining
Assert the length of an array in response body
How do you write a Postman test to assert that the response body array has exactly 5 items?
Postman
pm.test('Response array length is 5', () => {
const jsonData = pm.response.json();
// Write assertion here
});Attempts:
2 left
💡 Hint
Use the correct property to get array length in JavaScript.
✗ Incorrect
Option A correctly uses 'length' property to check array size. Option A uses 'length' as a method which is invalid. Options C and D use non-existent properties 'size' and 'count'.
❓ Predict Output
advanced2:00remaining
What is the result of this Postman test script?
Consider the following response body and test script. What will be the test result (pass or fail)?
Postman
/* Response body JSON */ [ {"id": 1, "active": true}, {"id": 2, "active": false}, {"id": 3, "active": true} ] /* Test script */ pm.test('All users are active', () => { const jsonData = pm.response.json(); pm.expect(jsonData.every(user => user.active)).to.be.true; });
Attempts:
2 left
💡 Hint
Check if every user object has active set to true.
✗ Incorrect
The response array has one user with active false (id 2), so 'every' returns false and the assertion fails.
❓ locator
advanced2:00remaining
Choose the correct JSON path to select all 'name' fields in an array response
Given a response body array of objects with a 'name' property, which JSON path expression correctly selects all 'name' values?
Attempts:
2 left
💡 Hint
Use the wildcard to select all elements in the array, then access the 'name' property.
✗ Incorrect
Option A correctly uses '$[*].name' to select the 'name' property from each element in the root array. Option A is invalid syntax. Option A selects 'name' from root object, not array elements. Option A has incorrect bracket usage.
❓ framework
expert3:00remaining
Identify the correct Postman test script to assert sorted order of array by 'score'
You receive a response body array of objects with a numeric 'score' property. Which Postman test script correctly asserts that the array is sorted in ascending order by 'score'?
Postman
pm.test('Array is sorted by score ascending', () => {
const jsonData = pm.response.json();
// Write assertion here
});Attempts:
2 left
💡 Hint
Check each element compared to the previous one to confirm ascending order.
✗ Incorrect
Option C uses 'every' to check each element's score is greater or equal to the previous, correctly asserting ascending order. Option C misuses reduce and will cause a runtime error. Option C sorts the array in place, changing it, so the comparison fails. Option C sorts scores as strings, causing incorrect comparison.