AngularJS Testing Cookbook

AngularJS Testing Cookbook

Language: English

Pages: 193

ISBN: 1783983744

Format: PDF / Kindle (mobi) / ePub


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

About This Book

  • Learn how to build a solid and more reliable AngularJS codebase through test-driven development using clearly defined recipes
  • Understand how to set up and configure your development environment for unit and end-to-end testing of AngularJS applications
  • Over 50 hands-on recipes to help you build a solid foundation in AngularJS

Who This Book Is For

This book is intended for developers who have an understanding of the basic principles behind both AngularJS and test-driven development. You, as a developer, are interested in eliminating the fear related to either introducing tests to an existing codebase or starting out testing on a fresh AngularJS application. If you're a team leader or part of a QA team with the responsibility of ensuring full test coverage of an application, then this book is ideal for you to comprehend the full testing scope required by your developers. Whether you're new to or are well versed with AngularJS, this book will guarantee a complete understanding of your application code and help reduce the cost of bugs.

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

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.

WordPress: Pushing the Limits

Web Design in a Nutshell: A Desktop Quick Reference (3rd Edition)

Programming Google App Engine with Java

Web Mapping Illustrated: Using Open Source GIS Toolkits

Web Design Blueprints

 

 

 

 

 

 

 

 

 

 

 

 

scope', inject(function ($rootScope, $controller) {})); 2. Next, create a new scope object: var scope = $rootScope.$new(); 3. Register a new instance of our controller providing the scope object created in step 2 and a $routeParams object with an id value: $controller('EmceesCtrl', { $scope: scope, $routeParams: { id: '1' } }); 4. Finally, add the expectation that the scope id has the same value we provided to the $routeParams object: expect(scope.id).toEqual('1'); 50 Chapter 3 How it

filter using the $filter service providing our filter name (decimalAdjust) as the sole argument. In step 4, we call and provide the filter with the obligatory arguments and use the toBe matcher to determine test success or failure. See also ff The Testing a filter that formats seconds to a time string recipe ff The Using Protractor to test filter changes based on events recipe ff The Using Protractor to test filter changes based on input recipe 111 Testing Filters Testing a filter that

details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website, or added to any list of existing errata, under the Errata section of that title. Piracy Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the

Installing Protractor recipe in Chapter 1, Setup and Configuration. Please update your URL and port based on your configuration. How to do it… 1. Firstly, we need to ensure that Protractor navigates our browser to the correct URL, that is, our local server and port: beforeEach(function () { browser.get('http://0.0.0.0:8000/'); }); 2. Next, create a test stating our intention that the HTML displays the correct decimal value: it('should display the correct decimal value', function () {}); 3.

service makes use of the $http service's get() method (https:// docs.angularjs.org/api/ng/service/$http#get) that returns a promise with two methods specific to $http: success and error, as shown in the following code: .service('emcees', function($http) { return { getUKEmcees: function() { return $http.get('/emcees/uk'); } }; }); Also, ensure that you've loaded your module; consider the following example: beforeEach(module('chapter8')); 122 Chapter 8 How to do it… Follow these steps to test

Download sample

Download