Posts

Showing posts from May, 2012

Geta

Image
Geta
© 2010 Darren DeRidder. Originally uploaded by soto voce
Sandals for guests in the entryway of a ryokan. Kinosaki, Japan.

A Simple Introduction to Behavior Driven Development in NodeJS with Mocha

I recently had a chance to use the Mocha test framework for NodeJS on a large-ish project and wanted to provide a really simple introduction to it.  Mocha is a unit testing framework for NodeJS apps from TJ Holowaychuk.  As the successor to the popular Expresso test framework, it adds a number of new features. It supports both Test-Driven and Behavior-Driven development styles and can report test results in a variety of formats.

Mocha can be installed easily using npm. Assuming you have node and npm installed, you can install mocha as a global module using the -g flag to it will be available everywhere on the system.

npm -g install mocha
or perhaps

sudo npm -g install mocha
or, if you prefer a local install instead of a global install

npm install mocha
export PATH=./node_modules/.bin:$PATH

You're also going to want should.js, which you can install in your local project folder.

npm install should
Mocha, in addition to being a test framework, is a command-line utility that you run w…