Lightweight Javascript Test Runner for Node.js
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
lib
README

README


Writing tests is simple an easy with Ernest!

Example:

Start by requiring the Ernest module. Path may need to be altered depending on location of test files.



var ernest = require(‘geddy/geddy-core/scripts/ernest’);
var assert = require('assert);

Create an namespace (object-literal) to wrap your tests.



var myTests = {

  //preface each key with the word ‘test’

  testThatSomethingWorks : function(){

    var foo = ‘bar’;

    //use Node’s Assert module — last parameter is fail message that is displayed. 

    //By default, it uses what’s predefined in Ernest

    assert.ok(foo, this.fail); 

    assert.equal(foo, ‘bar’, this.fail);

  }

};

And, for the last bit, pass your new test to Ernest:



  ernest.execute(myTests);

If you want tests to be run via ‘make test’ — Save your tests in a directory called ‘tests’ in the module you’re testing.

That’s it!!! It’s that easy!

Tests can be run one of two ways:

run all tests: make test
individual tests: node path/to/test.js


Additionally I've included an example of tests that are actively being used in Geddy (http://www.github.com/mde/geddy).