O'Reilly logo

PhantomJS Cookbook by Rob Friesel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Running Mocha unit tests with PhantomJS

This recipe demonstrates how to run Mocha-based unit tests through PhantomJS as an alternative to Jasmine and QUnit.

Getting ready

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 our PATH
  • 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required