This recipe demonstrates how to run Mocha-based unit tests through PhantomJS as an alternative to Jasmine and QUnit.
To run this recipe, we will need the following items:
JavaScript code to test, and the tests for that code
Node.js and
npm
installed and on ourPATH
The Mocha test framework (included in
lib/mocha
)Note
Mocha is the "simple, flexible, and fun" JavaScript unit-testing framework that runs in Node.js or in the browser. It is open source (MIT licensed), and we can learn more about it at http://visionmedia.github.io/mocha/; we can install Mocha on the command line using
npm
, as follows:npm install --global mocha
The Chai assertion library (included in
lib/chai
)Note
Chai is a platform-agnostic BDD/TDD assertion library featuring several interfaces (for example,
should
,expect
, andassert
). It is open source (MIT licensed), and we can learn more about it at http://chaijs.com/; we can install Chai on the command line usingnpm
, as follows...