- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Assertions in Postman with Chai Assertion Library
There are Assertions in Postman with Chai Assertion Library. Assertions are used to check whether the expected and actual results are the same. If not, an Assertion error is thrown with an error message.
An Assertion returns a Boolean value. In Postman, Assertion is implemented in JavaScript. It is available in the Postman application automatically.
In Postman, the Assertions are incorporated under the Tests or Pre-Request Script tab. The documentation of the Chai library is available in the link − https://www.chaijs.com/.
Let us build an Assertion to verify if the text – Postman is present in an array.
pm.test["Text is present"], function(){ pm.expect(['Java', 'Postman']).to.include('Postman') })
Output
Let us build an Assertion to check if an array contents any element.
pm.test["Array contains element"], function(){ pm.expect(['Java', 'Postman']).to.be.an('array').that.is.not .empty })
Output
Let us implement an Assertion to check object properties with eql function. This function performs comparisons between properties of two objects.
pm.test("Equality", function(){ let i = { "subject" : "Postman" }; let j= { "subject" : "Cypress" }; pm.expect(i).to.not.eql(j);
Output
The object i has the property - Postman while the object j property has the property - Cypress. So not.eql Assertion returned a true value.
- Related Articles
- How to write Assertions in Postman with Chai Assertion Library?
- What are assertions in Selenium with python?
- Assertions in Java
- Assertions in Python
- Assertions in C#
- Postman with Newman & Jenkins
- Assertions in C/C++
- Understanding Assertions Cypress
- OAuth 2.0 Authorization with Postman
- What are assertions available to test relational comparisons in Selenium with python?
- The G Assertion in Perl
- Lookbehind Assertions JavaScript Regular Expressions
- GUID in Postman
- How to set a Test in Postman with JavaScript Method?
- What is Type Assertion in TypeScript?
