You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
I have some unit tests for a directive that worked fine until I migrated to the latest release candidate. The tests pass without incident even under the RC, but fail if the main module includes 'ngAnimate', even where, as here, the application has no animations defined or used. Somehow a routine synchronous test goes funky.
The application works fine when run in production.
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';};}};});
The test
...
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();});
...
(just remove ngAnimate in the app.js definition of the main module to see tests pass).
The problem seems to have something to do with the recent changes to ng-class and animation. No amount of research seems to work. What's going on?
Pure aside: I note that the angular.mock.animate decorator doesn't seem to get installed merely by adding angular-mock.js to my build in ordinary course. ($animate does not have flushNext coded.) Do I need to do anything special, or load in any particular order to make the config work right?
The text was updated successfully, but these errors were encountered:
In an effort to keep ngAnimate animation onComplete events as async, a timeout is called. In this case, before the blue class is added, the timeout has to be fired, but angular-mocks.js buffers the result.
The solution may be to change this inside of ngAnimate. So the timeout only occurs on the callback and not when there is no animation. @IgorMinar what do you think?
@wizardwerdna unfortunately with the recent commits to ngAnimate, you are required to call $timeout.flush() once or twice during each animation for each directive as well as $rootScope.$digest() if you use $animate directly.
My suggestion is to avoid including ngAnimate as a dep in your test code unless you really want to perform testing on it.
jamesdaily
pushed a commit
to jamesdaily/angular.js
that referenced
this issue
Jan 27, 2014
I have some unit tests for a directive that worked fine until I migrated to the latest release candidate. The tests pass without incident even under the RC, but fail if the main module includes 'ngAnimate', even where, as here, the application has no animations defined or used. Somehow a routine synchronous test goes funky.
The application works fine when run in production.
The following plnkr illustrates the problem:
http://plnkr.co/edit/ZpdjrlZMADdeGxKYpR9Z?p=preview
The directive
The test
(just remove ngAnimate in the app.js definition of the main module to see tests pass).
The problem seems to have something to do with the recent changes to ng-class and animation. No amount of research seems to work. What's going on?
Pure aside: I note that the angular.mock.animate decorator doesn't seem to get installed merely by adding angular-mock.js to my build in ordinary course. ($animate does not have flushNext coded.) Do I need to do anything special, or load in any particular order to make the config work right?
The text was updated successfully, but these errors were encountered: