Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.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
Javascript 角度单元测试指令中的注入滤波器_Javascript_Angularjs_Unit Testing - Fatal编程技术网

Javascript 角度单元测试指令中的注入滤波器

Javascript 角度单元测试指令中的注入滤波器,javascript,angularjs,unit-testing,Javascript,Angularjs,Unit Testing,这可能很简单,但我在任何地方都找不到任何解决方案。现在我有一个使用过滤函数的指令。一切都很好,但我正在尝试为它创建一个单元测试,它给了我 Error: [$injector:unpr] Unknown provider: inArrayFilterProvider <- inArrayFilter 这是我的单元测试 "严格使用", describe('myApp.directives module', function() { beforeEach(module('myApp.di

这可能很简单,但我在任何地方都找不到任何解决方案。现在我有一个使用过滤函数的指令。一切都很好,但我正在尝试为它创建一个单元测试,它给了我

Error: [$injector:unpr] Unknown provider: inArrayFilterProvider <- inArrayFilter
这是我的单元测试

"严格使用",

describe('myApp.directives module', function() {

  beforeEach(module('myApp.directives'));

  describe('navbar directive', function() {
      var $scope,controller,template;
      beforeEach(inject(function($rootScope,$compile,$location,$filter,$templateCache){
          $scope = $rootScope.$new();

          $templateCache.put('partials/navbar.html','I am here');
          spyOn($location,'path').andReturn("/festivals");
          var element = angular.element('<div  data-navbar=""></div>');
          template = $compile(element)($scope);
          controller = element.controller;
          $scope.$digest();
      }));
    it('Check Festival nav', function() 
    {
        expect($scope.isActive('/festivals')).toBeTruthy();
    });
  });
});
描述('myApp.directives module',函数(){
在每个模块之前(模块('myApp.directions');
描述('navbar指令',函数(){
var$范围、控制器、模板;
beforeach(注入函数($rootScope、$compile、$location、$filter、$templateCache){
$scope=$rootScope.$new();
$templateCache.put('partials/navbar.html','I am here');
spyOn($location,'path')。andReturn(“/festival”);
变量元素=角度元素(“”);
模板=$compile(元素)($scope);
控制器=element.controller;
$scope.$digest();
}));
它('检查节日导航',函数()
{
expect($scope.isActive('/festions')).toBeTruthy();
});
});
});
我想当用inArray调用spyOn时,我必须对其进行过滤,并返回一个模拟值,但不确定如何执行。 谢谢

修复。 我必须包括我的主要模块,它具有inArray功能

describe('myApp.directives module', function() {
var $filter;
  beforeEach(module('myApp'),function(_$filter_){
      $filter = _$filter_;
  });
.../*Rest as Before*/
...
...});
describe('myApp.directives module', function() {
var $filter;
  beforeEach(module('myApp'),function(_$filter_){
      $filter = _$filter_;
  });
.../*Rest as Before*/
...
...});