lundi 2 février 2015

Call a controller function from Karma and Jasmine testing

This is my angular controller :-



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

$scope.test= function() {
$scope.testVar = 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.testVar when calling test',
function() {
expect(scope.testVar).toBeUndefined();
scope.test();
expect(scope.testVar).toBedefined();
});
});


Getting an error when i run that test case :- scope.test() 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