node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



Chai assertions for phantomjs scripts


npm install phantom-chai chai --save-dev

Usage in phantomjs script

    var chai = require('phantom-chai')()
        , assert = chai.assert;
    var page = webpage.create();'http://localhost/test', function (status) {
        assert.equal(status, 'success');
        assert.equal(page.title, 'My page');

If any of the assertions throws, script will log the error and the stack and will terminate. Internally phantom.exit(1) is called.

You can pass custom teardown function in options, e.g. to delete test data and to kill child processes:

    var chai = require('phantom-chai')({ teardown: teardown });
    function teardown() {

At the moment only 'assert' style assertions are supported.


chai is NOT a dependency of phantom-chai, it should be installed separately.

It allows you using any version of chai with phantom-chai and upgrading chai without upgading phantom-chai.