lundi 8 juin 2015

Stub angular service in directive unit test

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?

Aucun commentaire:

Enregistrer un commentaire