O'Reilly logo

AngularJS Testing Cookbook by Simon Bailey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing service data using mock helpers

The Using spies to test HTTP POST requests recipe uses a mock data object to be sent along with the POST request. However, it's quite feasible that your application may repeatedly use specific objects in different locations, for example, sending within HTTP requests, or using as mock responses, and so on.

This can result in you mocking out the same (or similar) objects in multiple test files. There are different approaches that you can take to overcome this issue. In this recipe, you will see how to DRY (http://en.wikipedia.org/wiki/Don%27t_repeat_yourself) up some of your test code in the Getting ready section and then how to use this mock data in a test. In this recipe, you will also learn how to resolve ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required