AngularJS Testing Cookbook

Eliminate volatile code by taking control and understanding how to test AngularJS applications

AngularJS Testing Cookbook

This ebook is included in a Mapt subscription
Simon Bailey

Eliminate volatile code by taking control and understanding how to test AngularJS applications
$23.99
$29.99
RRP $23.99
RRP $29.99
eBook
Print + eBook
Subscribe and access every Packt eBook & Video.
 
  • 4,000+ eBooks & Videos
  • 40+ New titles a month
  • 1 Free eBook/Video to keep every month
Start Free Trial
 
Preview in Mapt

Book Details

ISBN 139781783983742
Paperback180 pages

Book Description

AngularJS stepped up to offer a comprehensive solution to frontend development with minimal dependencies and a clear set of objectives.

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.

Table of Contents

Chapter 1: Setup and Configuration
Introduction
Creating a basic AngularJS application
Running a simple test using Jasmine
Installing Protractor
Running a simple test using Protractor
Installing Karma
Running tests using Karma
Installing Testem
Running tests using Testem
Automating test runners using Grunt
Automating test runners using Gulp
Chapter 2: Getting Started with Testing and AngularJS
Introduction
Loading a module
Writing a test spec
Debugging AngularJS code
Mocking injected instances using an object
Mocking injected instances using spies
Chapter 3: How to Test Navigation and Routing
Introduction
Getting started with testing using ngRoute
Testing route parameters with ngRoute
Getting started with testing using ui-router
Testing the transitioning state with ui-router
Testing URL parameters with ui-router
Testing page loading using Protractor
Testing navigation using Protractor
Testing redirection using Protractor
Chapter 4: Testing Controllers
Introduction
Setting up for testing a controller
Testing the initial state of a scope object
Testing the initial state of a scope object with Protractor
Testing interactive scope changes with Protractor
Testing navigation scope changes with Protractor
Chapter 5: Testing User Interaction and Directives
Introduction
Starting with testing directives
Setting up templateUrl
Searching elements using selectors
Accessing basic HTML content
Accessing repeater content
Scope changes based on user input
Scope changes based on DOM events
Class changes based on window properties
Directive changes on interaction using Protractor
Chapter 6: Using Spies to Test Events
Introduction
Testing event dispatches
Testing the handling of dispatched events
Testing the handling of external events
Testing the handling of callbacks
Testing events using Protractor
Chapter 7: Testing Filters
Introduction
Testing a filter that formats a number as text
Testing a filter that formats seconds to a time string
Using Protractor to test filter changes based on input
Using Protractor to test filter changes based on events
Chapter 8: Service and Factory Testing with Mocks and Spies
Introduction
Getting started with testing a service
Testing HTTP GET requests using $httpBackend
Testing HTTP POST requests using $httpBackend
Using spies to test HTTP GET requests
Using spies to test HTTP POST requests
Testing service data using mock helpers
Testing rejected $http promises
Testing constants
Using Protractor to test HTTP requests
Chapter 9: A Brief Look at Testing Animations
Introduction
Synchronous testing of animations
Testing animations with ngAnimateMock
Asynchronous testing of animations

What You Will Learn

  • Install and configure all required tools and dependencies to begin testing your AngularJS application
  • Understand the anatomy of a unit test and integrate core fundamentals to begin testing AngularJS
  • Discover navigation and routing using both the AngularJS router and the ui-router library
  • Explore how to test controllers
  • Analyze test directives and user-based interaction
  • Explain the uses of spies and test events
  • Test services using mocks and spies
  • Animate test cases, both synchronously and asynchronously

Authors

Table of Contents

Chapter 1: Setup and Configuration
Introduction
Creating a basic AngularJS application
Running a simple test using Jasmine
Installing Protractor
Running a simple test using Protractor
Installing Karma
Running tests using Karma
Installing Testem
Running tests using Testem
Automating test runners using Grunt
Automating test runners using Gulp
Chapter 2: Getting Started with Testing and AngularJS
Introduction
Loading a module
Writing a test spec
Debugging AngularJS code
Mocking injected instances using an object
Mocking injected instances using spies
Chapter 3: How to Test Navigation and Routing
Introduction
Getting started with testing using ngRoute
Testing route parameters with ngRoute
Getting started with testing using ui-router
Testing the transitioning state with ui-router
Testing URL parameters with ui-router
Testing page loading using Protractor
Testing navigation using Protractor
Testing redirection using Protractor
Chapter 4: Testing Controllers
Introduction
Setting up for testing a controller
Testing the initial state of a scope object
Testing the initial state of a scope object with Protractor
Testing interactive scope changes with Protractor
Testing navigation scope changes with Protractor
Chapter 5: Testing User Interaction and Directives
Introduction
Starting with testing directives
Setting up templateUrl
Searching elements using selectors
Accessing basic HTML content
Accessing repeater content
Scope changes based on user input
Scope changes based on DOM events
Class changes based on window properties
Directive changes on interaction using Protractor
Chapter 6: Using Spies to Test Events
Introduction
Testing event dispatches
Testing the handling of dispatched events
Testing the handling of external events
Testing the handling of callbacks
Testing events using Protractor
Chapter 7: Testing Filters
Introduction
Testing a filter that formats a number as text
Testing a filter that formats seconds to a time string
Using Protractor to test filter changes based on input
Using Protractor to test filter changes based on events
Chapter 8: Service and Factory Testing with Mocks and Spies
Introduction
Getting started with testing a service
Testing HTTP GET requests using $httpBackend
Testing HTTP POST requests using $httpBackend
Using spies to test HTTP GET requests
Using spies to test HTTP POST requests
Testing service data using mock helpers
Testing rejected $http promises
Testing constants
Using Protractor to test HTTP requests
Chapter 9: A Brief Look at Testing Animations
Introduction
Synchronous testing of animations
Testing animations with ngAnimateMock
Asynchronous testing of animations

Book Details

ISBN 139781783983742
Paperback180 pages
Read More

Read More Reviews