Testing for PhantomJS scripts.
Note that PhantomJS must be installed. It is not a directly stated dependency because many developers choose to install phantomjs separately (outside of node/npm), and an explicit dependency on PhantomJS would entail downloading an additional copy of the PhantomJS binary.
With npm do:
npm install phantomjs-test-provisions
There is a default example which can run immediately:
Also there is an example using grunt (see
To add tests to a separate PhantomJS module, add a
tests/run-tests.js that looks like this:
// load and setup phantomjs-test-provisionsvar testprovisions = require"./../node_modules/phantomjs-test-provisions";var jasmine = testprovisionsjasmine;var jasmineConsoleReporter = testprovisionsjasmineConsoleReporter;var chai = testprovisionschai;var should = chaishould;var it = jasmineit;var describe = jasminedescribe;/* Remember to setup the module if it's expected to be available later. Itcould also be required() inside each individual test. */var mymodule = require"./../../mymodule"// include the custom test files herephantominjectJs"./test-sample.js";// launch the testsvar jasmineEnv = testprovisionsconfigureJasmine;jasmineEnvexecute;
Then write tests in
describe"phantomjs-test-provisions example test"it"should exist"shouldexistmymodule;;;