Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
83 lines (62 sloc) 2.31 KB

Test Tools

A set of Node.js application testing tools we use at Fireworks Project. We use Mocha for most of our testing, but you should find these tools useful for most of the Node.js automated testing tools out there.


Add 'test-tools' entry into the package.json file of your project or install it with npm:

npm install test-tools


There are no command line utilities as part of this package.



A function used to create wrapped test methods which can be passed into test frameworks that which expect functions to be passed in. This is useful for a couple reasons:

  • Bind the test function to a utility object for easy access to assertion functions.
  • Keep an assertion count and check it when the test is over.

Here's an example useing Mocha:

var TEST = require('test-tools');
var T = TEST.test;

describe('something', function () {
    it('should do something', T(function (done) {
        // If anything more or less than 9 assertions are run, then
        // an assertion error will be thrown.

        // Asynchronous testing is done as usual
        // but *don't forget to call done()*
        setTimeout(function () {
            return done();
        }, 12);

        this.throws(function () {
            throw new Error('testing');

        this.doesNotThrow(function () { return; });

        // if `done()` is not called in an asynchronous closure, like it
        // was above, then make sure it is called here instead.

All the assertion methods bound to this are proxied to the Node.js assertion methods of the same name. For more info on their usage, consult the Node.js docs.


Underscore.js is exposed as _, Underscore, UN and underscore.


Run the tests with:

rake test

Of course you'll need to install Node.js and Rake first.

Something went wrong with that request. Please try again.