Mocha is a simple yet wonderfully designed testing framework for Node.js.

In agile development, developers write tests before implementing a feature. When you are discussing a story for a feature, you should already be writing the test cases.

Here is a guide by Brian Stoner. After installing mocha and such, you can create a MakeFile like this:


  @NODE_ENV=test ./node_modules/.bin/mocha \
    --reporter $(REPORTER) \

  @NODE_ENV=test ./node_modules/.bin/mocha \
    --reporter $(REPORTER) \
    --growl \

.PHONY: test test-w

(In case you wonder what .PHONY is..)

You can run your tests with:

$ make test

Another javascript library you should use together with mocha is should.js.

Should.js replaces assert library with more human-like language eg.

An interesting thing to note: should.js extend object prototype!! While this is usually dangerous, should.js extend object with a should, and only that, thus safer.




Back to Home