0
0
Postmantesting~20 mins

Using Chai assertion library in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Chai Assertion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
assertion
intermediate
2:00remaining
Identify the correct Chai assertion for checking response status
You want to verify that the HTTP response status code is exactly 200 using Chai in Postman tests. Which assertion is correct?
Postman
pm.test('Status code is 200', function () {
    pm.response.to.have.status(200);
});
Apm.expect(pm.response.code).to.equal(200);
Bpm.expect(pm.response.status).to.eql(200);
Cpm.expect(pm.response.statusCode).to.be(200);
Dpm.expect(pm.response.code).to.be.equalTo(200);
Attempts:
2 left
💡 Hint
Check the exact property name for status code in Postman response object.
Predict Output
intermediate
2:00remaining
What is the test result of this Chai assertion?
Given the response JSON body: {"success": true, "count": 5}, what will be the result of this test in Postman?
Postman
pm.test('Check success and count', function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.success).to.be.true;
    pm.expect(jsonData.count).to.be.above(3);
});
ATest fails because success is not a boolean.
BTest fails because count is not above 5.
CTest fails due to syntax error in assertion.
DTest passes because success is true and count is 5 which is above 3.
Attempts:
2 left
💡 Hint
Check the values in the JSON and the assertion conditions carefully.
locator
advanced
2:00remaining
Choose the best way to assert a nested JSON property exists
You receive this JSON response: {"user": {"id": 123, "profile": {"name": "Alice"}}}. Which Chai assertion correctly verifies that the 'name' property exists inside 'profile'?
Postman
var jsonData = pm.response.json();
Apm.expect(jsonData.user.profile).to.have.property('name');
Bpm.expect(jsonData.user['profile.name']).to.exist;
Cpm.expect(jsonData.user.profile.name).to.exist;
Dpm.expect(jsonData.user).to.have.property('profile.name');
Attempts:
2 left
💡 Hint
Check how to assert nested properties with Chai's 'property' method.
🔧 Debug
advanced
2:00remaining
Find the cause of this failing Chai assertion
This Postman test fails with an error: "TypeError: Cannot read property 'length' of undefined". What is the likely cause?
Postman
pm.test('Array length check', function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.items.length).to.be.above(0);
});
AThe 'length' property is not a valid Chai assertion.
BThe 'items' property is missing or undefined in the response JSON.
CThe 'to.be.above' method is used incorrectly.
DThe pm.response.json() method returns a string, not an object.
Attempts:
2 left
💡 Hint
Check if the property you access exists before using its attributes.
framework
expert
2:00remaining
Which Chai assertion style is used in Postman tests by default?
Postman supports multiple Chai assertion styles. Which style is the default and recommended for writing tests in Postman scripts?
AShould style (e.g., response.should.have.status(200))
BAssert style (e.g., assert.equal(response.status, 200))
CExpect style (e.g., expect(response.code).to.equal(200))
DVerify style (e.g., verify(response.status === 200))
Attempts:
2 left
💡 Hint
Look at common examples in Postman test scripts.