Testing with Postman: Chai Assertions

Search for a command to run...

No comments yet. Be the first to comment.
In this series I will cover testing with postman and using it for automation.
Postman has many built in Javascript libraries. Moment is one of the more useful ones for getting dates such as today's date or tomorrow's. Creating a Date with Moment Moment is another tool build into postman that can be used for your test. This is ...
I have spent the last few weeks adding AI agents to my Playwright framework. Specifically Playwright's planner, generator, and healer, running locally through Claude Code. The Playwright agents explor

I decided to do a dump or a one stop shop for learning postman. You can go through my other post or just read this one. Testing Basics So to get started with postman you will need your API url and whether it is a GET, POST, PUT, DELETE or various oth...

Next is to setup a DevOps job you can go here to learn how to do that. For this section we will focus on the Execute shell and newman. With this I suggest going through Postman's official documentation found here. This takes your postman game and ups...

Schema is something you need to test to make sure when they need a string that it is indeed a string. If you google postman and schema checking you will also find a cool tool called tv4. Do not use this as it is out dated and no longer supported. Ple...

Another javascript library built into Postman is Lodash. #Looping Arrays with Lodash Sometimes you will want to iterate through an array. Maybe your response itself is an array. Luckily there is an easy for loop that can be used. This is use for wher...

Postman uses the Chai Assertion Library so familiarize yourself with it.
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.
pm.test("Date is correct format", function() {
pm.expect(jsonData.date).to.match(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$/, "Date should be 0000-00-00T00:00:00Z not " + jsonData.date);
});
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.
And
pm.expect(jsonData.smallsString).to.be.a('string', 'smallsString is not a string')
.and.be.lengthOf(5, 'smallsString is not 5 in length')
.and.to.contain('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