Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 指令单元测试中的存根角服务_Angularjs_Unit Testing_Angularjs Directive_Angularjs Service_Stub - Fatal编程技术网

Angularjs 指令单元测试中的存根角服务

Angularjs 指令单元测试中的存根角服务,angularjs,unit-testing,angularjs-directive,angularjs-service,stub,Angularjs,Unit Testing,Angularjs Directive,Angularjs Service,Stub,我有这样一个指示: app.directive('myDirective', ['my', function(myService){ return { restrict: 'E', scope: { resourcePath: '=' }, priority: 999, transclude: true, template: '<ng-transclude ng-if="func()"></ng-transclud

我有这样一个指示:

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);
        };
    }
};}]);

如何存根myService并将其注入到指令依赖项中?

对于控制器,您自己创建控制器很容易

对于指令依赖项,必须使用
$provide
覆盖默认实现并提供虚拟依赖项

beforeEach(module(function ($provide) {
    $provide.service('my', function () { 
        this.checkSomething= function() { };
    });
}));
beforeEach(module(function ($provide) {
    $provide.service('my', function () { 
        this.checkSomething= function() { };
    });
}));