I created an angular custom directive with a service called scriptingService in it. The goal is to mock the service call out with a spyOn. This is part of the test:
beforeEach(inject(function ($rootScope, $compile,_scriptingService_) {
scope = $rootScope.$new();
scope.row = 1;
scriptingService = _scriptingService_;
Restangular = _Restangular_;
spyOn(Restangular, 'all').and.callThrough();
spyOn(scriptingService, 'getScript').and.callThrough();
element = angular.element('<ul id="rows" ui-list="row">');
$compile(element)(scope);
scope.$digest();
}));
This is the directive code:
.directive('uiList', [
function(scriptingService) {
return {
scope: {
lengthModel: '=uiList'
},
link: function(scope, elm, attrs) {
scope.$watch('lengthModel', function(newVal) {
scope.test=2;
console.log('kut');
scriptingService.getScript(request).then(function(scripts){
scope.scripts = scripts;
});
});
}
};
}
]);
However I am getting an error:
RestangularProvider <- Restangular <- scriptingService
How can I mock the scriptingService and make sure the method was called? Plunker ref:http://plnkr.co/edit/CDc7EV?p=preview