Testing for PhantomJS scripts.


PhantomJS unit testing module installable through npm.

Makes your PhantomJS javascript spaghetti testable, reusable and maybe even production-ready.

phantomjs-test-provisions uses a standalone version of Jasmine. This package is largely based off of code in the upstream PhantomJS repository. As a separate node module, it's a quick option for developers interested in adding testing to their PhantomJS outer context (JavaScriptCore environment).


Note that PhantomJS must be installed. It must be available in $PATH.


With npm do:

npm install phantomjs-test-provisions

This adds unit testing to PhantomJS modules. To make use of the global script, use:

npm install -g phantomjs-test-provisions


Write tests in tests/spectacles.js like this: = function() {
    describe("phantomjs-test-provisions example test", function() {
        var mymodule = require("./../../mymodule");
        it("should exist", function() {

Then run tests like this (if it was installed through npm install -g):


Using the script through a relative path is also possible and it could be added to a Gruntfile or package.json like so:


writing tests

There are multiple styles available, provided by Chai including assert and expect/should.

who tests the testers?

There is also a default example which can run immediately for this project:

npm test

Also there is an example using grunt (see Gruntfile.js):

grunt test

or even: