Reputation: 1314
I have a directive as this:
app.directive('myDirective', ['my', function(myService){
return {
restrict: 'E',
scope: {
resourcePath: '='
},
priority: 999,
transclude: true,
template: '<ng-transclude ng-if="func()"></ng-transclude>',
link: function($scope){
$scope.func = function(){
return permissionsService.checkSomething(true);
};
}
};}]);
and this is the service:
angular.module('services.my', []).service('my', ['$http', function myService($http) {
//public:
this.checkSomething = function (param) {
return param;
};}]);
How can i stub myService and inject it into the directive dependencies?
Upvotes: 1
Views: 181
Reputation: 42669
For controller it is easy as you create the controller yourself.
For directive dependency you would have to use $provide
to override the default implementation and provide a dummy dependency
beforeEach(module(function ($provide) {
$provide.service('my', function () {
this.checkSomething= function() { };
});
}));
Upvotes: 1