Unit Testing Javascript with QUnit and Sinon.js

In this blog post, Rob Stevenson-Leggett gives a detail presentation on how to start some simple Javascript unit tests using QUnit as the test framework and Sinon.js as a mocking framework. QUnit is a JavaScript test suite used by the jQuery project to test its code and plugins but is capable of testing any generic JavaScript code and even capable of testing JavaScript code on the server-side. Sinon.JS is a standalone test spies, stubs and mocks for JavaScript. It has no dependencies and works with any unit testing framework.

The posts provides a step by step process to create an html file which will be your test harness, create a file called tests.js containing the javascript test, use Sinon.js to mock external code and examine the arguments a stubbed function was called with.