Ben Weese

Testing with Postman: Chai Assertions

Postman uses the Chai Assertion Library so familiarize yourself with it.

Using Chai Match Assertion

You can define a format for your response using Regex and the match assertion. Below is an example of a data format for a mysql date.

Date Format

pm.test("Date is correct format", function() {
            pm.expect(^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$/, "Date should be 0000-00-00T00:00:00Z not " +;

Multiple Assertions

When using multiple assertions on a single data point you don’t need to create an a new pm.expect. Instead use and and a proper error message. Since a proper error message is there you will know what has happened.


pm.expect(jsonData.smallsString)'string', 'smallsString is not a string'), 'smallsString is not 5 in length')'den', 'smallsString does not contain den')

See the below Chai Assertion Library link for more on Chai Assertions.


Postman Quick Reference Guide
Chai Assertion Library
Regex Cheat Sheet
Postman: The Complete Guide on Udemy

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.