You are previewing AngularJS Testing Cookbook.
O'Reilly logo
AngularJS Testing Cookbook

Book Description

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

In Detail

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.

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

  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. AngularJS Testing Cookbook
      1. Table of Contents
      2. AngularJS Testing Cookbook
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Setup and Configuration
        1. Introduction
        2. Creating a basic AngularJS application
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        3. Running a simple test using Jasmine
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        4. Installing Protractor
          1. Getting ready
          2. How to do it…
          3. There's more…
          4. See also
        5. Running a simple test using Protractor
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        6. Installing Karma
          1. Getting ready
          2. How to do it…
          3. There's more…
          4. See also
        7. Running tests using Karma
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        8. Installing Testem
          1. Getting ready
          2. How to do it…
          3. See also
        9. Running tests using Testem
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        10. Automating test runners using Grunt
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        11. Automating test runners using Gulp
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
      9. 2. Getting Started with Testing and AngularJS
        1. Introduction
        2. Loading a module
          1. Getting ready
          2. How to do it…
          3. There's more…
        3. Writing a test spec
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        4. Debugging AngularJS code
          1. Getting ready
          2. How to do it…
          3. See also
        5. Mocking injected instances using an object
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        6. Mocking injected instances using spies
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
      10. 3. How to Test Navigation and Routing
        1. Introduction
        2. Getting started with testing using ngRoute
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        3. Testing route parameters with ngRoute
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        4. Getting started with testing using ui-router
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        5. Testing the transitioning state with ui-router
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        6. Testing URL parameters with ui-router
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        7. Testing page loading using Protractor
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        8. Testing navigation using Protractor
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        9. Testing redirection using Protractor
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
      11. 4. Testing Controllers
        1. Introduction
        2. Setting up for testing a controller
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        3. Testing the initial state of a scope object
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        4. Testing the initial state of a scope object with Protractor
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        5. Testing interactive scope changes with Protractor
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        6. Testing navigation scope changes with Protractor
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
      12. 5. Testing User Interaction and Directives
        1. Introduction
        2. Starting with testing directives
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        3. Setting up templateUrl
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        4. Searching elements using selectors
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        5. Accessing basic HTML content
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        6. Accessing repeater content
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        7. Scope changes based on user input
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        8. Scope changes based on DOM events
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        9. Class changes based on window properties
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        10. Directive changes on interaction using Protractor
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
      13. 6. Using Spies to Test Events
        1. Introduction
        2. Testing event dispatches
          1. Getting ready…
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also…
        3. Testing the handling of dispatched events
          1. Getting ready…
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also…
        4. Testing the handling of external events
          1. Getting ready…
          2. How to do it…
          3. How it works…
          4. See also…
        5. Testing the handling of callbacks
          1. Getting ready…
          2. How to do it…
          3. How it works…
        6. Testing events using Protractor
          1. Getting ready…
          2. How to do it…
          3. How it works…
          4. See also…
      14. 7. Testing Filters
        1. Introduction
        2. Testing a filter that formats a number as text
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        3. Testing a filter that formats seconds to a time string
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        4. Using Protractor to test filter changes based on input
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        5. Using Protractor to test filter changes based on events
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
      15. 8. Service and Factory Testing with Mocks and Spies
        1. Introduction
        2. Getting started with testing a service
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        3. Testing HTTP GET requests using $httpBackend
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        4. Testing HTTP POST requests using $httpBackend
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        5. Using spies to test HTTP GET requests
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        6. Using spies to test HTTP POST requests
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        7. Testing service data using mock helpers
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        8. Testing rejected $http promises
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        9. Testing constants
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        10. Using Protractor to test HTTP requests
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
      16. 9. A Brief Look at Testing Animations
        1. Introduction
        2. Synchronous testing of animations
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        3. Testing animations with ngAnimateMock
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        4. Asynchronous testing of animations
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
      17. Index