单元测试淡出指令 - 看不到正确的CSS类添加-angular&安培;茉莉 [英] unit testing fading out directive - cannot see the right CSS class added -angular & jasmine

查看:195
本文介绍了单元测试淡出指令 - 看不到正确的CSS类添加-angular&安培;茉莉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图测试非常简单的指令,我做了。

i'm trying to test the very simple directive i have made.

.directive('cssnotification', [ '$timeout', function($timeout) {
return {
    restrict:'A',
    link:function(scope, element, attrs) {

        scope.$watch('success',function(newVal ,oldVal){

            if(newVal){                                
                $timeout(function(){                        

                         scope.success = false;                                                      

                },1000);
            }
        },true)
    }  
}
 }])

该指令使一些元素,1秒,之后是可见的 - 淡出了出来。
(这里是小提琴演示该问题)

我知道,执行fadingOut动画角应添加类NG隐藏添加到的元素,那就是我试图测试。在它的工作原理浏览器(从小提琴手除去角嘲笑,它会运行),但在单元测试 - 由于某些原因测试失败

I know that for perform the fadingOut animation angular should add "ng-hide-add" class to the element, and that is that i'm trying to test. In the browser it works (remove angular-mocks from fiddler and it will run) but in unit tests - this test fails for some reason.

我猜它是与NG-动画的注射...

I guess it has something to do with injecting of ng-animate...

由于转发

推荐答案

找到了解决办法:等待一段时间,直到nganimate添加类:

Found the solution: to wait some time until nganimate adds the class:

      $timeout(function(){
          expect(e.hasClass('ng-hide-add')).toEqual(true);
      },100)

这里是小提琴

这篇关于单元测试淡出指令 - 看不到正确的CSS类添加-angular&安培;茉莉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆