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

Getting started with testing using ngRoute


To configure routes, we need to use the $routeProvider function; this maps paths from the current URL to a route object. The route object can include a controller, an HTML template, and other properties (for more information, visit https://docs.angularjs.org/api/ngRoute/provider/$routeProvider). This recipe will show you how to lay the initial groundwork to begin testing your routing logic, such as mapped values, and assigning route parameters to scope.

Getting ready

Ensure that you have included the angular-route.js file as documented in this chapter's introduction. You can use the following example code as a basis for testing in this recipe or use an existing application that includes ngRoute:

  1. Load the ngRoute module in your application by adding it as a dependent module:

      angular.module('chapter3.ngRoute', ['ngRoute'])
  2. Add a config block that will get applied during the application's bootstrap process. The config block injects providers, so this...