Skip to main content

Testing with Postman: Chai Assertions

Published 1 min readMarkdown
Part of seriesTesting with Postman
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(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);
        });

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.

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.

Links

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

About the author

  • I build automation frameworks — not just tests. Over 10 years I've designed and shipped production testing platforms across payment, insurance, and healthcare domains. My instinct is always toward architecture: clean abstractions, maintainable patterns, and systems that don't fall apart when the product scales. What I'm working on now: - A Claude/Playwright agent framework that generates test cases directly from Jira tickets - Concurrency and race-condition coverage for financial transactions - A modular Playwright/JavaScript platform covering UI and 20+ API service integrations with 100+ JSON schema validators I've built production automation in Playwright, Geb/Spock, Rest-Assured, and Selenium across payment, insurance, and healthcare domains. When a stack isn't working, I replace it. When a pattern is wrong, I fix it. If the automation problem is interesting, I'm probably already thinking about it.

No comments yet. Be the first to comment.

More from this blog