Socket
Socket
Sign inDemoInstall

chai-api

Package Overview
Dependencies
54
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    chai-api

api assertion library


Version published
Maintainers
1
Install size
5.92 MB
Created

Readme

Source

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

Keywords

FAQs

Last updated on 13 Dec 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc