Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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);
✗ 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;
AThat responseJson.success is a string
BThat responseJson.success is true
CThat responseJson.success is false
DThat responseJson.success exists
✗ Incorrect
It checks that the success property in responseJson is exactly true.
Which Chai style uses natural language syntax?
Aexpect
Bassert
Cshould
Dverify
✗ 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'?
What will happen if the response body is 'Operation was successful'?
medium
A. Test will pass only if response code is 200
B. Test will fail because 'success' is not exactly matched
C. Test will throw a syntax error
D. Test will pass because 'success' is included in the response
Solution
Step 1: Understand the assertion used
The assertion checks if the response text includes the substring 'success'.
Step 2: Check if 'success' is in 'Operation was successful'
The word 'successful' contains 'success' as a substring, so the assertion passes.
Final Answer:
Test will pass because 'success' is included in the response -> Option D
Quick Check:
Substring check includes 'success' [OK]
Hint: Include checks pass if substring exists anywhere [OK]
Common Mistakes:
Expecting exact match instead of substring
Confusing syntax error with assertion failure
Assuming status code affects this test
4. Identify the error in this Postman test code snippet:
pm.test('Status is 404', () => {
pm.expect(pm.response.status).to.equal(404);
});
medium
A. pm.response.status is not the correct property for status code
B. to.equal should be to.be.equal
C. pm.test should be pm.expect
D. Missing semicolon after pm.test
Solution
Step 1: Check the property used for status code
The correct property for status code in Postman is pm.response.code, not pm.response.status.
Step 2: Confirm Chai syntax correctness
The to.equal syntax is correct and pm.test is used properly.
Final Answer:
pm.response.status is not the correct property for status code -> Option A
Quick Check:
Status code property is pm.response.code [OK]
Hint: Use pm.response.code for status, not pm.response.status [OK]
Common Mistakes:
Using pm.response.status instead of pm.response.code
Adding unnecessary 'to.be' in assertion
Confusing pm.test with pm.expect
5. You want to write a Postman test that asserts the JSON response has a property userId with a value greater than 100. Which code snippet correctly uses Chai assertions to do this?