Tools for Promises Unit Testing

Venkat.R
32.9K views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

MochaJs

Mocha is a JavaScript test framework running on node.js, featuring browser support, asynchronous testing, test coverage reports, and use of any assertion library. It can be used with libraires like should.js, expect.js and chai.js.

Simple Mocha Example

ChaiJs

Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework.

Simple Chai Example

SinonJs

SinonJs is a standalone library for test spies, stubs and mocks for JavaScript. Works with any unit testing framework.

Simple Sinon Example

Installation

Use below any one command to install Mocha, Chai and Sinon Module and these must to be installed as Dev Dependencies modules, because it’s not required when application running in the server but during build.

$ npm i -D mocha chai sinon
            or
$ npm install mocha chai sinon --save-dev

Code Coverage

If you are very much interested on how much code covered during unit testing. Try Istanbul which make test coverage simple with various types of report format.

$ npm i -D nyc
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content