AngularJS Testing Cookbook

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

AngularJS Testing Cookbook

Simon Bailey

Eliminate volatile code by taking control and understanding how to test AngularJS applications
Mapt Subscription
FREE
$29.99/m after trial
eBook
$16.80
RRP $23.99
Save 29%
Print + eBook
$29.99
RRP $29.99
What do I get with a Mapt Pro subscription?
  • Unlimited access to all Packt’s 5,000+ eBooks and Videos
  • Early Access content, Progress Tracking, and Assessments
  • 1 Free eBook or Video to download and keep every month after trial
What do I get with an eBook?
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with Print & eBook?
  • Get a paperback copy of the book delivered to you
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with a Video?
  • Download this Video course in MP4 format
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
$0.00
$16.80
$29.99
$29.99p/m after trial
RRP $23.99
RRP $29.99
Subscription
eBook
Print + eBook
Start 30 Day Trial
Subscribe and access every Packt eBook & Video.
 
  • 5,000+ eBooks & Videos
  • 50+ 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

Recommended for You

Mastering Web Application Development with AngularJS Book Cover
Mastering Web Application Development with AngularJS
$ 26.99
$ 5.40
AngularJS Web Application Development Blueprints Book Cover
AngularJS Web Application Development Blueprints
$ 29.99
$ 21.00
AngularJS UI Development Book Cover
AngularJS UI Development
$ 26.99
$ 18.90
AngularJS Web Application Development Cookbook Book Cover
AngularJS Web Application Development Cookbook
$ 29.99
$ 6.00
AngularJS by Example Book Cover
AngularJS by Example
$ 24.99
$ 17.50
Responsive Web Design with HTML5 and CSS3 Book Cover
Responsive Web Design with HTML5 and CSS3
$ 23.99
$ 4.80