# 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

```javascript
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
```javascript
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](https://postman-quick-reference-guide.readthedocs.io/en/latest/index.html)
[Chai Assertion Library](https://www.chaijs.com/api/bdd/)
[Regex Cheat Sheet](https://www.rexegg.com/regex-quickstart.html)
[Postman: The Complete Guide on Udemy](https://www.udemy.com/postman-the-complete-guide/)
