¡GoConqr estrena diseño! Cuéntanos qué te parece.

Apuntes

Unit Testing

James Drummond Angular A-Level Inglés 1 página

Contenido del apunte (1)

Página 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-templates

Keep 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');

});

});

Información

Descripción
A-Level Angular Apunte sobre Unit Testing, creado por James Drummond el 04/05/2015.
Creado por
James Drummond
Visitas
27
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?