Unit Testing

Beschreibung

A-Level Angular Notiz am Unit Testing, erstellt von James Drummond am 04/05/2015.
James Drummond
Notiz von James Drummond, aktualisiert more than 1 year ago
James Drummond
Erstellt von James Drummond vor mehr als 9 Jahre
2
0

Zusammenfassung der Ressource

Seite 1

Mainly this is to do with unit testing directives, in particular directives with external templates (which have to be compiled to be made available)See: http://www.portlandwebworks.com/blog/testing-angularjs-directives-handling-external-templatesKeep in mind that, in terms of functionality, it is *much* easier to test controllers than it is to test directives.- Therefore keep the functionality in a directive to a minimum. If the directive needs a function that has anything to do with business logic then that function should be inherited from the controller (where it can be more easily tested).

Unit testing a controller with an asynchronous service - Mock the service and inject it into the controller.- REMEMBER YOU MUST CALL scope.$digest(); AFTER THE ASYNCHRONOUS CALL IS MADE IN THE SERVICE TO UPDATE ANY VARIABLES THAT ARE CHANGED BY THE CALL

Testing controlleras syntax (and a cleaner way of injecting controllers) describe('MainCtrl', function() { var scope; beforeEach(function(){ module('myModule'); inject(function($controller, $rootScope) { scope = $rootScope.$new(); var localInjections = { $scope: scope, }; $controller('MainCtrl as main', localInjections); }); }); it('should expose title', function() { expect(scope.main.title).equal('Some title'); });});

Zusammenfassung anzeigen Zusammenfassung ausblenden

ähnlicher Inhalt

The Princeton Review Chapter 9 Rotational Motion
Anibal Santamaria
Angular
Kingsley Bawuah
Angular Nuts and Bolts
James Drummond
Scope and Inheritance in Angular
James Drummond
Angular application scaffolding
James Drummond
Hold Fast To Dreams
11913505
Directives and scope
James Drummond
Jasmine and Maddie
alison.bowers
FE Web Applications Components
Juan Carlos Joya Carvajal
Fluxo buscaCliente
Alex José Silva
How Angular works
James Drummond