Recall & Review
beginner
What is the Chai assertion library used for in Postman tests?
Chai is used to write clear and readable assertions to check if API responses meet expected conditions during Postman tests.
Click to reveal answer
beginner
How do you write a basic assertion to check if a response status code is 200 using Chai in Postman?
pm.test('Status code is 200', function () { pm.response.to.have.status(200); });
Click to reveal answer
intermediate
What does the Chai assertion 'expect(response).to.have.property("name")' check for?
It checks that the response object has a property called "name".
Click to reveal answer
intermediate
Explain the difference between 'expect' and 'assert' styles in Chai.
Both are assertion styles in Chai. 'expect' reads like natural language (e.g., expect(value).to.equal(5)), while 'assert' uses functions (e.g., assert.equal(value, 5)). Both check conditions but differ in syntax.
Click to reveal answer
beginner
How can you check if a JSON response body contains a specific string using Chai in Postman?
Use: pm.test('Body contains string', function () { pm.expect(pm.response.text()).to.include('expected string'); });
Click to reveal answer
Which Chai assertion checks if a response status is 404?
✗ Incorrect
The correct syntax to check status code is pm.response.to.have.status(404);
What does this assertion check? pm.expect(responseJson.success).to.be.true;
✗ Incorrect
It checks that the success property in responseJson is exactly true.
Which Chai style uses natural language syntax?
✗ Incorrect
'expect' style reads like natural language, e.g., expect(value).to.equal(5).
How do you check if response body contains the word 'success'?
✗ Incorrect
pm.expect(pm.response.text()).to.include('success'); correctly checks if the response text contains 'success'.
What is the purpose of pm.test() in Postman tests?
✗ Incorrect
pm.test() defines a test with a descriptive name and a function containing assertions.
Describe how to write a Chai assertion in Postman to verify the response status code and a JSON property value.
Think about checking status first, then accessing JSON body and asserting a property.
You got /4 concepts.
Explain the difference between 'expect' and 'assert' styles in Chai and when you might prefer one over the other.
Consider how each style reads and how easy it is to understand.
You got /4 concepts.