Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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 ngAnimate干扰了v1.2.0-rc.2中与ngClass相关的单元测试,以及_Javascript_Unit Testing_Angularjs_Angularjs Directive - Fatal编程技术网

Javascript ngAnimate干扰了v1.2.0-rc.2中与ngClass相关的单元测试,以及

Javascript ngAnimate干扰了v1.2.0-rc.2中与ngClass相关的单元测试,以及,javascript,unit-testing,angularjs,angularjs-directive,Javascript,Unit Testing,Angularjs,Angularjs Directive,我对一个指令进行了一些单元测试,在迁移到最新的候选版本之前,这些测试一直运行良好。即使在RC下,测试也会顺利通过,但如果主模块包含“ngAnimate”,即使在这里,应用程序没有定义或使用动画,测试也会失败。不知怎的,一个常规的同步测试变得很古怪 该应用程序在生产环境中运行时运行良好 以下说明了问题: 指令 app.directive('directive', function(){ return { template: '<dir ng-class="blues()">

我对一个指令进行了一些单元测试,在迁移到最新的候选版本之前,这些测试一直运行良好。即使在RC下,测试也会顺利通过,但如果主模块包含“ngAnimate”,即使在这里,应用程序没有定义或使用动画,测试也会失败。不知怎的,一个常规的同步测试变得很古怪

该应用程序在生产环境中运行时运行良好

以下说明了问题:

指令

app.directive('directive', function(){
  return {
    template: '<dir ng-class="blues()">'+
                'This text is {{blues()}}, but the test failed.'+
               '</dir>',
    restrict: 'E',
    replace: true,
    link: function(scope, element, attrs){
      scope.blues = function(){return 'blue';};
    }
  };
});
app.directive('directive',function(){
返回{
模板:“”+
'此文本为{{blues()}},但测试失败。'+
'',
限制:'E',
替换:正确,
链接:函数(范围、元素、属性){
scope.blues=function(){return'blue';};
}
};
});
测试

...
beforeEach(inject(function($rootScope, $compile) {
  scope = $rootScope.$new();
  element = $compile('<directive></directive>')(scope);
  $rootScope.$digest();
}));
...
it('should have the text be blue', function() {
  expect(element.hasClass('blue')).toBeTruthy();
});
...
。。。
beforeach(注入(函数($rootScope,$compile){
scope=$rootScope.$new();
元素=$compile(“”)(范围);
$rootScope.$digest();
}));
...
它('文本应为蓝色',函数(){
expect(element.hasClass('blue')).toBeTruthy();
});
...
(只需删除Plunker中主模块的app.js定义中的ngAnimate,即可看到测试通过)

这个问题似乎与最近对ng类和动画的更改有关。再多的研究似乎都不管用。发生什么事了


纯粹的旁白:我注意到angular.mock.animate装饰程序似乎并不是仅仅通过在我的构建中添加angular-mock.js来安装的。($animate没有flushNext编码。)我是否需要做任何特殊的操作,或者以任何特定的顺序加载以使配置正常工作?

我看到了完全相同的问题-应用程序工作正常,但如果ngAnimate作为应用程序的依赖项包含,则单元测试失败-angular#1.2.4