Like a Genie from the Lamp:
Headless JavaScript Testing with Jasmine and PhantomJS
Example code to accompany my presentation on using Jasmine and PhantomJS for lightning-fast JavaScript unit tests, a talk that was given at the 2012 VT Code Camp.
Abstract:
Jasmine is a mature BDD test framework for JavaScript, and though powerful and feature-rich in its own right, you are often still shackled to a browser window to conduct your tests. Tools like Selenium WebDriver make automated testing possible, but they are difficult to set up, cumbersome to use, and worst of all slow. Wouldn't it be nice if you could execute your tests as part of your build? And have those tests before completed in seconds? With PhantomJS ("the headless WebKit") that wish has come true. In this talk we will introduce the Jasmine BDD test framework, introduce PhantomJS, and demonstrate how to execute your Jasmine tests in PhantomJS for lightning fast results.
Running the Code
- Download/install PhantomJS; make sure it's on your
PATH
. - Checkout this repository;
cd
into the repo and run these commands:git submodule init
git submodule update
- From within the repo:
phantomjs lib/jasmine-reporters/test/phantomjs-testrunner.js $(pwd)/test/all-tests-spec.htm
Resources
- Slides from the talk
- also: rate me on SpeakerRate
- blog post redux at blog.founddrama.net: headless JavaScript unit testing with Jasmine and PhantomJS
- Jasmine
- Rebecca Murphey's jQuery Testing with Jasmine (screencast)
- PhantomJS
- larrymyers/jasmine-reporters
- jcarver989/phantom-jasmine (An alternative test runner.)
- Ben Cherry's Writing Testable JavaScript