https://github.com/postmanlabs/chai-postman
Chai plugin to assert on Postman Collections
https://github.com/postmanlabs/chai-postman
Last synced: 9 months ago
JSON representation
Chai plugin to assert on Postman Collections
- Host: GitHub
- URL: https://github.com/postmanlabs/chai-postman
- Owner: postmanlabs
- License: apache-2.0
- Created: 2017-10-11T09:18:06.000Z (over 8 years ago)
- Default Branch: develop
- Last Pushed: 2024-10-29T10:50:19.000Z (about 1 year ago)
- Last Synced: 2025-04-02T06:08:31.136Z (10 months ago)
- Language: JavaScript
- Size: 767 KB
- Stars: 29
- Watchers: 15
- Forks: 13
- Open Issues: 35
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.yaml
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# chai-postman [](https://travis-ci.com/postmanlabs/chai-postman) [](https://codecov.io/gh/postmanlabs/chai-postman)
[Chai plugin](http://chaijs.com/api/plugins/) to assert on Postman Collections
## Install
```bash
$ npm install chai-postman --save-dev
```
## Usage
In order to use this plugin, ensure that you have [postman-collection](https://www.npmjs.com/package/postman-collection)
and [lodash](https://www.npmjs.com/package/lodash) installed.
```javascript
var _ = require('lodash'),
chai = require('chai'),
sdk = require('postman-collection'),
chaiPostman = require('chai-postman'),
req,
res,
expect = chai.expect;
chai.use(chaiPostman(sdk, _));
// create postman-collection request and response instances
req = new sdk.Request({
header: [{
key: 'Content-Type',
value: 'application/json; charset=utf-8'
}]
});
res = new sdk.Response({ code: 200 });
// request assertions
expect(req).to.be.a.postmanRequest;
expect(req).to.have.header('Content-Type'); // an optional second argument can also be provided to assert value
// response assertions
expect(res).to.be.a.postmanResponse;
expect(res).to.have.statusCode(200);
```
Check the [tests](https://github.com/postmanlabs/chai-postman/tree/develop/test/unit) for a complete reference.