Full-stack testing with PhantomJS
We have now written unit tests for logic at the core of our application and integration tests for our server-side routes. We don't yet have any automated tests that cover our views and client-side scripts as our manual testing throughout the previous chapters did.
We can write unit tests for client-side scripts using Mocha. However, all of our current client-side scripts interact with the server, so aren't good candidates for unit testing. Our manual tests are really full-stack tests of our whole application, including the interaction between the server and the client.
In order to achieve this in an automated test, we will need to use some form of browser automation. PhantomJS is a headless browser with a JavaScript API that allows us to automate it directly. We can write a simple test for our game page using this.
First, we'll install PhantomJS within our project by running the following on the command line:
> npm install phantomjs-prebuilt --save-dev