0
0
Postmantesting~5 mins

Using Chai assertion library in Postman - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Apm.response.status(404);
Bpm.response.to.be.status(404);
Cpm.response.to.have.status(404);
Dpm.response.has.status(404);
What does this assertion check? pm.expect(responseJson.success).to.be.true;
AThat responseJson.success is a string
BThat responseJson.success is true
CThat responseJson.success is false
DThat responseJson.success exists
Which Chai style uses natural language syntax?
Aexpect
Bassert
Cshould
Dverify
How do you check if response body contains the word 'success'?
Apm.expect(pm.response.text()).to.include('success');
Bpm.response.to.have.body('success');
Cpm.expect(pm.response.body).to.have.string('success');
Dpm.response.body.includes('success');
What is the purpose of pm.test() in Postman tests?
ATo set environment variables
BTo send an API request
CTo log response data
DTo define a test case with a name and function
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.