Testing with Jasmine and headless browser PhantomJS
In the following section, we will look at BDD tests implementation with Jasmine and PhantomJS, using the example of the Imaginary application we built in Chapter 8, Building "Imaginary" – An Application with Instagram-like Image Filters.
Introduction to the Jasmine
Jasmine is available as a Node.js module and also as a library that we could use in the browser. It comes with its assertion methods.
It's a module, so it could be installed via the Node.js package manager, npm
:
$ npm install jasmine-node -g
The command sets up Jasmine globally, so we can run jasmine-node in every directory of our choice. The tests could be organized into different files placed in one folder or subfolders. The only requirement is to end our file names with spec.js
, for example, testing-picture-capture.spec.js
or testing-picture-list.spec.js
.
Let's look at Jasmine on a particular example.
Writing unit tests with Jasmine
Let's imagine that we want to build an application...