To most people building websites, writing JavaScript means copying-and-pasting a couple of jQuery snippets onto a page to get a dropdown to animate. While the proliferation of JavaScript frameworks has helped make code more organized, testing front-end code is still far from the norm. We will go through the different types of testing, how to set up a test runner, writing unit and integration tests, and refactoring code to make it testable. You will leave this talk fitter, happier, and less likely to create globals.
To play with the demo, download/clone this repository, then follow the directions below.
Open demo/jasmine/SpecRunner.html
in your browser. It will run the incomplete tests by default – see demo/jasmine/complete.js
for the final versions.
The pending specs can be found in demo/selenium/browser_spec.rb
. The complete version is in demo/selenium/complete_spec.rb
. Requires Firefox.
bundle install
rspec demo/selenium/browser_spec.rb
Test-Drive Your JavaScript by Aidan Feldman is licensed under a Creative Commons Attribution 4.0 International License.