问题
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)
}
}
}])
This directive makes some element to be visible for 1 second and after that - fades it out. (here is the fiddle that demonstrates the problem)
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.
I guess it has something to do with injecting of ng-animate...
Thanks forwards
回答1:
Found the solution: to wait some time until nganimate adds the class:
$timeout(function(){
expect(e.hasClass('ng-hide-add')).toEqual(true);
},100)
here is fiddle
来源:https://stackoverflow.com/questions/20781057/unit-testing-fading-out-directive-cannot-see-the-right-css-class-added-angula