Chai Assertion Library
Chai assertion library is available by default in the Postman. So when you are writing chai assertions, then don't worry about other processes of installation. The main feature of Postman assertions is that they write the tests with English sentences, which is human readable. So it is very easy to read and user friendly.
If you would like to learn more about the Chai Assertion Library, there is an official website for that. You can visit this https://www.chaijs.com/.
Writing Assertions using Chai Assertion Library.
Copy the following URL in the URL text field.
In the above example, we are checking that if 100 is equal to 200 or not. The response is failed, which is obvious.
Just edit the code with the following code and see the response again.
Since 100 equal to 100. The test is passed.
Here, we will check the given number is in an array or not.
Here, you can see that the test is passed because, in the array list of 100, 200, and 300 has 300.
In this assertion, we will verify the object.
The test is passed because on both objects, names are equal.
In the above code, we have used eql(). Postman offers both methods eql() and equal(). But both methods are different. equal() is used to compare the objects, and eql() is used to compare the properties of the objects. In this case, eql() compared the name property of the object.
Try to edit the last line of code with pm.expect(x).to.equal(y), and see the response.
The above test failed because we have used equal(), which compares the object, not the property of the object.