Testing

Mocha

> npm i mocha -g

> mocha

test folder

Chai

> npm i chai --save-dev

Assert

vs

Should

vs

Expect

Assert

var assert = require('chai').assert
  , foo = 'bar'
  , beverages = { tea: [ 'chai', 'matcha', 'oolong' ] };

assert.typeOf(foo, 'string'); // without optional message
assert.typeOf(foo, 'string', 'foo is a string'); // with optional message
assert.equal(foo, 'bar', 'foo equal `bar`');
assert.lengthOf(foo, 3, 'foo`s value has a length of 3');
assert.lengthOf(beverages.tea, 3, 'beverages has 3 types of tea');

Expect

var expect = require('chai').expect
  , foo = 'bar'
  , beverages = { tea: [ 'chai', 'matcha', 'oolong' ] };

expect(foo).to.be.a('string');
expect(foo).to.equal('bar');
expect(foo).to.have.lengthOf(3);
expect(beverages).to.have.property('tea').with.lengthOf(3);

Should

var should = require('chai').should() //actually call the function
  , foo = 'bar'
  , beverages = { tea: [ 'chai', 'matcha', 'oolong' ] };

foo.should.be.a('string');
foo.should.equal('bar');
foo.should.have.lengthOf(3);
beverages.should.have.property('tea').with.lengthOf(3);

Assert, Expect

interfaces do not modify Object.prototype

 

Should

interface modifies Object.prototype

The assert and expect interfaces support custom messages just about everywhere. For instance:

The message "foo should be true" will be output together with the failed assertion if the assertion fails. You don't get the opportunity to set a custom message with the should interface.

assert.isTrue(foo, "foo should be true");
expect(foo, "foo should be true").to.be.true;

Nock

> npm i nock -D

SUT

System Under Test

Dependency

(collaborator)

Dependency

(collaborator)

Dependency

(collaborator)

Under construction

Module

SUT

Istanbul

> npm i istanbul -g

> istanbul cover _mocha

> istanbul cover node_modules/mocha/bin/_mocha -- -R spec

Supertest

> npm i supertest

Testing

By Shuhratbek Mamadaliyev

Testing

  • 1,007