Book Image

AngularJS Testing Cookbook

By : Simon Bailey
Book Image

AngularJS Testing Cookbook

By: Simon Bailey

Overview of this book

<p>AngularJS stepped up to offer a comprehensive solution to frontend development with minimal dependencies and a clear set of objectives.</p> <p>This book follows the AngularJS philosophy and offers guidance on how to approach testing components that make up the AngularJS framework. At the start of the book, you will explore how to configure your system to run unit and end-to-end tests. Following this, you'll become familiar with fundamental principles on testing AngularJS with Jasmine. Then, you'll understand how spies can enable you to test your code with greater coverage and simplicity throughout your application. The final result is an AngularJS application that is tested with integrity, helping facilitate a cleaner and more reliable codebase.</p>
Table of Contents (16 chapters)
AngularJS Testing Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Mocking injected instances using spies


In the Mocking injected instances using an object recipe in this chapter, we stated that if the module you're testing has other module dependencies, you need to maintain isolation, as well as ensure that they are resolved appropriately. Jasmine provides functions called spies (http://jasmine.github.io/2.0/introduction.html#section-Spies). Spies are used by tests to imitate to be functions or objects and offer the ability to then track calls made to the spy, plus query arguments that may also have been provided. They have their own set of special matchers that enhance testing against expectations. This additional set of features augment our testing capabilities offering a greater range of expectations than normally available without spies. Once you understand the concept behind Jasmine spies, you will realize they are a powerful tool to use within your tests. To further enhance Jasmine spies, I recommend that you look at the Sinon.JS library (http:/...