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

Searching elements using selectors


Directives, as you should know, attach special behavior to a DOM element. When AngularJS compiles and returns the element on which the directive is applied, it is wrapped by either jqLite or jQuery. This exposes an API on the element, offering many useful methods to query the element and its contents. In this recipe, you will learn how to use these methods to retrieve elements using selectors.

Getting ready

Follow the logic to define a beforeEach() function with the relevant logic to set up a directive as outlined in the Starting with testing directives recipe in this chapter. For this recipe, you can replicate the template that I suggested in the first recipe's There's more… section. For the purpose of this recipe, I tested against a property on scope named deejay:

var deejay = {
  name: 'Shortee',
  style: 'turntablism'
};

You can replace this with whatever code you have within the directive you're testing.

How to do it…

  1. First, create a basic test to establish...