CHAPTER 22 Testing DOM Access


  • Writing UI unit tests in Jasmine
  • Using jQuery to interact with the DOM in unit tests
  • Ensuring UI events execute the correct event handlers
  • Using a Profiler to identify opportunities for optimization


You can find the code downloads for this chapter at on the Download Code tab. The files are in the Chapter 22 download and are individually named according to the filenames noted throughout this chapter.

We’ve occupied many pages of this book describing how unit tests can help ensure the reliability of non-visual components of a web application, namely the JavaScript conference’s website. There’s no doubt that components of the website that don’t have a user interface, such as the attendeeRegistrationService, should have associated unit test suites.

Users of the website, however, aren’t aware that attendeeRegistrationService exists. Even though users interact with the service, they don’t do so directly: They interact with it via the website’s UI, presented via a web browser.

It’s all well and good for an application to function correctly, but world-class software must please the end user. That means the user interface must function smoothly and quickly.


Unit tests for JavaScript that interacts with the browser’s document object model, or DOM, are one way to ensure that a web application’s UI functions properly. ...

Get Reliable JavaScript: How to Code Safely in the World's Most Dangerous Language now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.