Writing asynchronous tests in It is just as easy as writing synchronous tests.

Lets modify Person to make get older async

varPerson=function(name,age){

this.name= name;

this.age= age;

this.getOlder=function(years,next){

setTimeout(function(){

this.age=this.age+ years;

next(null,this);

}.bind(this), years *500);

};

};

Now that getOlder is async lets test it

In this example a promise is the return value. If you have used comb, Q, promises-extedned or any other framework that uses
Promises then this will feel pretty natural to you. The test will wait for the promise to resolve before continuing any other tests.

var p =require("promise-extended");

it.describe("#getOlder",function(it){

//return promise

it.should("not apply negative numbers",function(){

var ret =newp.promise();

var person =newPerson("bob",1);

person.getOlder(-2,function(err,person){

assert.equal(person.age,1);

ret.callback();

});

returnret.promise();

});

});

In this example the should callback accepts a next(err) argument which is a function that should be called when the current test is done. So if next is invoked with a first argument other than null or undefined then
it is assumed that the test errored.

it also supports the concept of a context, which is a set of functionality that should belong to the current describe or suite tests but needs something extra like extra setup or tear down functionality.

In fact anything you can do withing the describe callback you can do in a context.

--cov-html : create coverage output in html, if an output path is included then the file will be written to that file otherwise it will defalt to ./coverage.html

--reporters : Display a list of reporters that are available

-h, --help : Displays help.

To run an entire suite

it -d ./mytests -r dotmatrix

To run an individual test

it ./mytests/person.test.js

Or

it -f "Person"

To run the #getOlder spec

it -f "Person:#getOlder"

You can alternatively run the test directly.

Note When running tests using the it.run() method, it will not automatically exit the program on completion, therefore if you still have items like DB connections still open your program will not exit.