chai-api
v1.0.4
Published
api assertion library
Downloads
12
Readme
chai-api
Assertion helper for api testing.
Features
- Use chai and request-promise.
- Require mocha-generators
- ES6 generator
Pre-install
npm install mocha-generators
How to use
require('mocha-generators').install();
const assert = require('chai').assert;
const api = require('chai-api')('http://some/api/url');
describe('API tests', function(){
it('should get result', function*(){
const req = {
body: { data: 'value'}
};
const result = yield api('GET', '/some/path', req);
assert.isOk(result, 'result should be defined');
});
it('should return isSuccess true', function*(){
const req = {
body: { data: 'value'}
};
yield api.success('GET', '/some/path', req);
});
});
APIs
api(method, path, req)
A generator to do api call.
api.success(method, path, req)
Do api call and assert for result.isSuccess
be true
.
api.notSuccess(method, path, req)
Do api call and assert for result.isSuccess
be false
.
ToDo
- Able to define expected result schema