CHAPTER 25

image

Unit Testing

In this chapter, I describe the facilities that AngularJS provides for unit testing and, in particular, the services that make it easy to isolate a piece of code from the rest of the AngularJS framework to enable thorough and consistent testing. Table 25-1 summarizes this chapter.

Table 25-1. Chapter Summary

Problem

Solution

Listing

Write a basic Jasmine unit test.

Use the Jasmine describe, beforeEach, it, and expect functions.

1–4

Prepare an AngularJS test.

Use the angular.mock.module method to load the module you want to test, and use the angular.mock.inject method to resolve dependencies.

5

Mock HTTP ...

Get Pro AngularJS 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.