lundi 2 février 2015

Unit testing call a function of a controller with Karma and Jasmine

This is my angular controller :-



angular.module('authoring-controllers', []).
controller('NavCtrl', function($scope, $location, BasketNavigationService) {
$scope.showBasketList = BasketNavigationService.showBasketList();
});


TEST class



describe('NavCtrl', function() {
var scope, $location, createController;

beforeEach(inject(function ($rootScope, $controller, _$location_) {
$location = _$location_;
scope = $rootScope.$new();

createController = function() {
return $controller('NavCtrl', {
'$scope': scope
});
};
}));

it('should create $scope.showBasketList when calling showBasketList',
function() {
expect(scope.showBasketList).toBeUndefined();
scope.showBasketList();
expect(scope.showBasketList).toEqual("Hello Ari");
});
});


Getting an error when i run that test case :- scope.showBasketList() is undefined..


If i removed BasketNavigationService functionality from controller then it is working..


Please help me to solve that karma test case.


Aucun commentaire:

Enregistrer un commentaire