Tuesday, February 3, 2015

Angular test primer in Jasmine

To test angular controller in Jasmine, need to use the angular mocks to inject module and controller
Then in the controllerSpec test js file, we can inject the controller and scope

describe('expense controller', function () {

var $controllerTestConstructor;
var scope;

beforeEach(module('app'));

beforeEach(inject(function($controller, $rootScope){



$controllerTestConstructor = $controller;

scope = $rootScope;

}));
 
it('should have three expense item', function () {
var ctrl = $controllerTestConstructor('expenseController', { $scope: scope });

expect(ctrl.expenseItems.length).toBe(3);

});

});
 

No comments: