Chapter 3. Testing JavaScript Applications

Test-driven development has become all the rage in software development over the past few years. By creating tests that are automated and repeatable, a developer can have confidence that the code is of high quality and that new changes will not break older features. Some proponents claim that tests should be written before the code they test.

Having a reliable set of tests is a vital part of any software development effort. It enables a developer to have confidence that code works once it’s written and will continue to work over time.

Testing has become a key element of development in most server-side development platforms. Solid test harnesses can be found in development environments for PHP, Java, Ruby, and so on. However, the standard method for testing in most of these languages does not work well for JavaScript. Let’s look at a few reasons why.

Server-side test suites generally have to test the program under just one set of environments. If a REST service is being built with Python, the tester can build the tests with several safe assumptions. For instance, he may know that it will run on Python version 3.0 on Linux, along with specific versions of all the supporting software.

The web application developer has no such confidence. Users will come to the site using Firefox, Internet Explorer, Chrome, Safari, and Opera—and several versions of each. So test suites must be able to handle testing across a number of browsers and operating systems, ...

Get Programming HTML5 Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.