node package manager


Toolkit and utilities for automated testing in Node.js

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 function which can be passed into test frameworks that use functions which expect a function 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:

describe('something', function () {
    it('should do something', 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

Underscore.js is exposed as ::_ and ::underscore

Run the tests with:

rake test

Of course you'll need to install Rake first.