mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
fix(ngAnimate): cut down on extra $timeout calls
This commit is contained in:
parent
d11a34a351
commit
4382df03fa
5 changed files with 38 additions and 169 deletions
|
|
@ -98,7 +98,7 @@ var $AnimateProvider = ['$provide', function($provide) {
|
|||
forEach(element, function(node) {
|
||||
parentNode.insertBefore(node, afterNextSibling);
|
||||
});
|
||||
$timeout(done || noop, 0, false);
|
||||
done && $timeout(done, 0, false);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -115,7 +115,7 @@ var $AnimateProvider = ['$provide', function($provide) {
|
|||
*/
|
||||
leave : function(element, done) {
|
||||
element.remove();
|
||||
$timeout(done || noop, 0, false);
|
||||
done && $timeout(done, 0, false);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -157,7 +157,7 @@ var $AnimateProvider = ['$provide', function($provide) {
|
|||
className :
|
||||
isArray(className) ? className.join(' ') : '';
|
||||
element.addClass(className);
|
||||
$timeout(done || noop, 0, false);
|
||||
done && $timeout(done, 0, false);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -178,7 +178,7 @@ var $AnimateProvider = ['$provide', function($provide) {
|
|||
className :
|
||||
isArray(className) ? className.join(' ') : '';
|
||||
element.removeClass(className);
|
||||
$timeout(done || noop, 0, false);
|
||||
done && $timeout(done, 0, false);
|
||||
},
|
||||
|
||||
enabled : noop
|
||||
|
|
|
|||
|
|
@ -283,7 +283,7 @@ angular.module('ngAnimate', ['ng'])
|
|||
enter : function(element, parent, after, done) {
|
||||
$delegate.enter(element, parent, after);
|
||||
performAnimation('enter', 'ng-enter', element, parent, after, function() {
|
||||
$timeout(done || noop, 0, false);
|
||||
done && $timeout(done, 0, false);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
@ -353,7 +353,7 @@ angular.module('ngAnimate', ['ng'])
|
|||
move : function(element, parent, after, done) {
|
||||
$delegate.move(element, parent, after);
|
||||
performAnimation('move', 'ng-move', element, null, null, function() {
|
||||
$timeout(done || noop, 0, false);
|
||||
done && $timeout(done, 0, false);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
@ -615,10 +615,11 @@ angular.module('ngAnimate', ['ng'])
|
|||
activeClassName += (i > 0 ? ' ' : '') + klass + '-active';
|
||||
});
|
||||
|
||||
$timeout(function() {
|
||||
element.addClass(activeClassName);
|
||||
$timeout(done, duration * 1000, false);
|
||||
},0,false);
|
||||
//this triggers a reflow which allows for the transition animation to kick in
|
||||
element.prop('clientWidth');
|
||||
element.addClass(activeClassName);
|
||||
|
||||
$timeout(done, duration * 1000, false);
|
||||
|
||||
//this will automatically be called by $animate so
|
||||
//there is no need to attach this internally to the
|
||||
|
|
|
|||
|
|
@ -321,29 +321,27 @@ describe('ngClass animations', function() {
|
|||
expect($animate.queue.length).toBe(0);
|
||||
|
||||
$rootScope.val = 'one';
|
||||
$timeout.flush();
|
||||
|
||||
$rootScope.$digest();
|
||||
$animate.flushNext('addClass');
|
||||
$animate.flushNext('addClass');
|
||||
$timeout.flush();
|
||||
expect($animate.queue.length).toBe(0);
|
||||
|
||||
$rootScope.val = '';
|
||||
$rootScope.$digest();
|
||||
$animate.flushNext('removeClass'); //only removeClass is called
|
||||
expect($animate.queue.length).toBe(0);
|
||||
$timeout.flush();
|
||||
|
||||
$rootScope.val = 'one';
|
||||
$rootScope.$digest();
|
||||
$animate.flushNext('addClass');
|
||||
$timeout.flush();
|
||||
expect($animate.queue.length).toBe(0);
|
||||
|
||||
$rootScope.val = 'two';
|
||||
$rootScope.$digest();
|
||||
$animate.flushNext('removeClass');
|
||||
$animate.flushNext('addClass');
|
||||
$timeout.flush();
|
||||
expect($animate.queue.length).toBe(0);
|
||||
}));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -133,15 +133,12 @@ describe("ngAnimate", function() {
|
|||
|
||||
expect(element.contents().length).toBe(0);
|
||||
$animate.enter(child, element);
|
||||
$timeout.flushNext(0);
|
||||
|
||||
if($sniffer.transitions) {
|
||||
expect(child.hasClass('ng-enter')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
expect(child.hasClass('ng-enter-active')).toBe(true);
|
||||
$timeout.flushNext(1000);
|
||||
$timeout.flush();
|
||||
}
|
||||
$timeout.flush();
|
||||
|
||||
expect(element.contents().length).toBe(1);
|
||||
}));
|
||||
|
|
@ -153,11 +150,9 @@ describe("ngAnimate", function() {
|
|||
$animate.leave(child);
|
||||
if($sniffer.transitions) {
|
||||
expect(child.hasClass('ng-leave')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
expect(child.hasClass('ng-leave-active')).toBe(true);
|
||||
$timeout.flushNext(1000);
|
||||
$timeout.flush();
|
||||
}
|
||||
$timeout.flush();
|
||||
|
||||
expect(element.contents().length).toBe(0);
|
||||
}));
|
||||
|
|
@ -186,9 +181,8 @@ describe("ngAnimate", function() {
|
|||
$animate.removeClass(child, 'ng-hide');
|
||||
if($sniffer.transitions) {
|
||||
expect(child.hasClass('ng-hide-remove')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
expect(child.hasClass('ng-hide-remove-active')).toBe(true);
|
||||
$timeout.flushNext(1000);
|
||||
$timeout.flush();
|
||||
}
|
||||
expect(child.hasClass('ng-hide-remove')).toBe(false);
|
||||
expect(child.hasClass('ng-hide-remove-active')).toBe(false);
|
||||
|
|
@ -203,11 +197,9 @@ describe("ngAnimate", function() {
|
|||
$animate.addClass(child, 'ng-hide');
|
||||
if($sniffer.transitions) {
|
||||
expect(child.hasClass('ng-hide-add')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
expect(child.hasClass('ng-hide-add-active')).toBe(true);
|
||||
$timeout.flushNext(1000);
|
||||
$timeout.flush();
|
||||
}
|
||||
$timeout.flush();
|
||||
expect(child).toBeHidden();
|
||||
}));
|
||||
|
||||
|
|
@ -221,46 +213,34 @@ describe("ngAnimate", function() {
|
|||
|
||||
//enter
|
||||
$animate.enter(child, element);
|
||||
$timeout.flushNext(0);
|
||||
expect(child.attr('class')).toContain('ng-enter');
|
||||
$timeout.flushNext(0);
|
||||
expect(child.attr('class')).toContain('ng-enter-active');
|
||||
$timeout.flushNext(1000);
|
||||
$timeout.flushNext(0);
|
||||
|
||||
//move
|
||||
element.append(after);
|
||||
$animate.move(child, element, after);
|
||||
$timeout.flushNext(0);
|
||||
expect(child.attr('class')).toContain('ng-move');
|
||||
$timeout.flushNext(0);
|
||||
expect(child.attr('class')).toContain('ng-move-active');
|
||||
$timeout.flushNext(1000);
|
||||
$timeout.flushNext(0);
|
||||
|
||||
//hide
|
||||
$animate.addClass(child, 'ng-hide');
|
||||
expect(child.attr('class')).toContain('ng-hide-add');
|
||||
$timeout.flushNext(0);
|
||||
expect(child.attr('class')).toContain('ng-hide-add-active');
|
||||
$timeout.flushNext(1000);
|
||||
$timeout.flushNext(0);
|
||||
|
||||
//show
|
||||
$animate.removeClass(child, 'ng-hide');
|
||||
expect(child.attr('class')).toContain('ng-hide-remove');
|
||||
$timeout.flushNext(0);
|
||||
expect(child.attr('class')).toContain('ng-hide-remove-active');
|
||||
$timeout.flushNext(1000);
|
||||
$timeout.flushNext(0);
|
||||
|
||||
//leave
|
||||
$animate.leave(child);
|
||||
expect(child.attr('class')).toContain('ng-leave');
|
||||
$timeout.flushNext(0);
|
||||
expect(child.attr('class')).toContain('ng-leave-active');
|
||||
$timeout.flushNext(1000);
|
||||
$timeout.flushNext(0);
|
||||
}));
|
||||
|
||||
it("should not run if animations are disabled",
|
||||
|
|
@ -276,12 +256,10 @@ describe("ngAnimate", function() {
|
|||
expect(element.text()).toBe('123');
|
||||
$animate.removeClass(element, 'ng-hide');
|
||||
expect(element.text()).toBe('123');
|
||||
$timeout.flushNext(0); //fires the addClass callback
|
||||
|
||||
$animate.enabled(true);
|
||||
|
||||
$animate.removeClass(element, 'ng-hide');
|
||||
$timeout.flushNext(0);
|
||||
expect(element.text()).toBe('memento');
|
||||
}));
|
||||
|
||||
|
|
@ -302,17 +280,13 @@ describe("ngAnimate", function() {
|
|||
child.css('display','block');
|
||||
child.removeClass('ng-hide');
|
||||
|
||||
$timeout.flushNext(0);
|
||||
if($sniffer.transitions) {
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flushNext(0);
|
||||
expect(element.children().length).toBe(1); //still animating
|
||||
$timeout.flushNext(1000);
|
||||
$timeout.flushNext(1000);
|
||||
}
|
||||
$timeout.flushNext(2000);
|
||||
$timeout.flushNext(2000);
|
||||
$timeout.flushNext(0);
|
||||
expect(child).toBeShown();
|
||||
|
||||
expect(element.children().length).toBe(0);
|
||||
|
|
@ -326,7 +300,6 @@ describe("ngAnimate", function() {
|
|||
child.addClass('custom-delay ng-hide');
|
||||
$animate.removeClass(child, 'ng-hide');
|
||||
if($sniffer.transitions) {
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flushNext(1000);
|
||||
}
|
||||
$timeout.flushNext(2000);
|
||||
|
|
@ -371,7 +344,6 @@ describe("ngAnimate", function() {
|
|||
$animate.addClass(element, 'custom-delay custom-long-delay');
|
||||
$timeout.flushNext(2000);
|
||||
$timeout.flushNext(20000);
|
||||
$timeout.flushNext(0);
|
||||
expect(element.hasClass('custom-delay')).toBe(true);
|
||||
expect(element.hasClass('custom-long-delay')).toBe(true);
|
||||
}));
|
||||
|
|
@ -392,12 +364,10 @@ describe("ngAnimate", function() {
|
|||
$animate.removeClass(element, 'ng-hide');
|
||||
|
||||
if($sniffer.transitions) {
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flushNext(1000);
|
||||
}
|
||||
$timeout.flushNext(2000);
|
||||
$timeout.flushNext(20000);
|
||||
$timeout.flushNext(0);
|
||||
|
||||
expect(element.hasClass('custom-delay')).toBe(true);
|
||||
expect(element.hasClass('custom-delay-add')).toBe(false);
|
||||
|
|
@ -437,7 +407,6 @@ describe("ngAnimate", function() {
|
|||
|
||||
$animate.removeClass(element, 'ng-hide');
|
||||
if ($sniffer.animations) {
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flushNext(4000);
|
||||
}
|
||||
expect(element).toBeShown();
|
||||
|
|
@ -461,7 +430,6 @@ describe("ngAnimate", function() {
|
|||
|
||||
$animate.removeClass(element, 'ng-hide');
|
||||
if ($sniffer.animations) {
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flushNext(6000);
|
||||
}
|
||||
expect(element).toBeShown();
|
||||
|
|
@ -485,7 +453,6 @@ describe("ngAnimate", function() {
|
|||
|
||||
$animate.removeClass(element, 'ng-hide');
|
||||
if ($sniffer.animations) {
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flushNext(2000);
|
||||
}
|
||||
expect(element).toBeShown();
|
||||
|
|
@ -511,7 +478,6 @@ describe("ngAnimate", function() {
|
|||
|
||||
$animate.removeClass(element, 'ng-hide');
|
||||
if ($sniffer.transitions) {
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flushNext(20000);
|
||||
}
|
||||
expect(element).toBeShown();
|
||||
|
|
@ -548,18 +514,15 @@ describe("ngAnimate", function() {
|
|||
$animate.removeClass(element, 'ng-hide');
|
||||
if($sniffer.animations) {
|
||||
expect(element.hasClass('ng-hide-remove')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
expect(element.hasClass('ng-hide-remove-active')).toBe(true);
|
||||
}
|
||||
|
||||
$animate.addClass(element, 'ng-hide');
|
||||
expect(element.hasClass('ng-hide-remove')).toBe(false); //added right away
|
||||
|
||||
$timeout.flushNext(0);
|
||||
|
||||
if($sniffer.animations) { //cleanup some pending animations
|
||||
expect(element.hasClass('ng-hide-add')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
expect(element.hasClass('ng-hide-add-active')).toBe(true);
|
||||
$timeout.flushNext(2000);
|
||||
}
|
||||
|
|
@ -584,8 +547,7 @@ describe("ngAnimate", function() {
|
|||
element.addClass('ng-hide');
|
||||
expect(element).toBeHidden();
|
||||
$animate.removeClass(element, 'ng-hide');
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flush();
|
||||
expect(element).toBeShown();
|
||||
|
||||
$animate.enabled(true);
|
||||
|
|
@ -595,10 +557,8 @@ describe("ngAnimate", function() {
|
|||
|
||||
$animate.removeClass(element, 'ng-hide');
|
||||
if ($sniffer.transitions) {
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flushNext(1000);
|
||||
}
|
||||
$timeout.flushNext(0);
|
||||
expect(element).toBeShown();
|
||||
}));
|
||||
|
||||
|
|
@ -618,10 +578,8 @@ describe("ngAnimate", function() {
|
|||
$animate.removeClass(element, 'ng-hide');
|
||||
if ($sniffer.transitions) {
|
||||
expect(element).toBeHidden();
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flushNext(2000);
|
||||
}
|
||||
$timeout.flush();
|
||||
expect(element).toBeShown();
|
||||
}));
|
||||
|
||||
|
|
@ -643,9 +601,7 @@ describe("ngAnimate", function() {
|
|||
element.addClass('ng-hide');
|
||||
$animate.removeClass(element, 'ng-hide');
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flushNext(0);
|
||||
expect(element).toBeShown();
|
||||
|
||||
$animate.enabled(true);
|
||||
|
||||
element.addClass('ng-hide');
|
||||
|
|
@ -653,10 +609,8 @@ describe("ngAnimate", function() {
|
|||
|
||||
$animate.removeClass(element, 'ng-hide');
|
||||
if ($sniffer.transitions) {
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flushNext(3000);
|
||||
}
|
||||
$timeout.flush();
|
||||
expect(element).toBeShown();
|
||||
}));
|
||||
|
||||
|
|
@ -677,7 +631,6 @@ describe("ngAnimate", function() {
|
|||
|
||||
$animate.removeClass(element, 'ng-hide');
|
||||
if ($sniffer.transitions) {
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flushNext(11000);
|
||||
}
|
||||
expect(element).toBeShown();
|
||||
|
|
@ -697,11 +650,9 @@ describe("ngAnimate", function() {
|
|||
$animate.removeClass(element, 'ng-hide');
|
||||
if($sniffer.transitions) {
|
||||
expect(element.hasClass('ng-hide-remove')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
expect(element.hasClass('ng-hide-remove-active')).toBe(true);
|
||||
$timeout.flushNext(1000);
|
||||
}
|
||||
$timeout.flushNext(0);
|
||||
expect(element.hasClass('ng-hide-remove')).toBe(false);
|
||||
expect(element.hasClass('ng-hide-remove-active')).toBe(false);
|
||||
expect(element).toBeShown();
|
||||
|
|
@ -709,7 +660,6 @@ describe("ngAnimate", function() {
|
|||
$animate.addClass(element, 'ng-hide');
|
||||
if($sniffer.transitions) {
|
||||
expect(element.hasClass('ng-hide-add')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
expect(element.hasClass('ng-hide-add-active')).toBe(true);
|
||||
}
|
||||
}));
|
||||
|
|
@ -732,28 +682,22 @@ describe("ngAnimate", function() {
|
|||
|
||||
element[0].className = 'abc';
|
||||
$animate.enter(element, parent);
|
||||
$timeout.flushNext(0);
|
||||
|
||||
if ($sniffer.transitions) {
|
||||
expect(element.hasClass('abc ng-enter')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
expect(element.hasClass('abc ng-enter ng-enter-active')).toBe(true);
|
||||
$timeout.flushNext(22000);
|
||||
}
|
||||
$timeout.flushNext(0);
|
||||
expect(element.hasClass('abc')).toBe(true);
|
||||
|
||||
element[0].className = 'xyz';
|
||||
$animate.enter(element, parent);
|
||||
$timeout.flushNext(0);
|
||||
|
||||
if ($sniffer.transitions) {
|
||||
expect(element.hasClass('xyz')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
expect(element.hasClass('xyz ng-enter ng-enter-active')).toBe(true);
|
||||
$timeout.flushNext(22000);
|
||||
}
|
||||
$timeout.flushNext(0);
|
||||
expect(element.hasClass('xyz')).toBe(true);
|
||||
}));
|
||||
|
||||
|
|
@ -773,10 +717,8 @@ describe("ngAnimate", function() {
|
|||
element.attr('class','one two');
|
||||
|
||||
$animate.enter(element, parent);
|
||||
$timeout.flushNext(0);
|
||||
if($sniffer.transitions) {
|
||||
expect(element.hasClass('one two ng-enter')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
expect(element.hasClass('one two ng-enter ng-enter-active')).toBe(true);
|
||||
expect(element.hasClass('one-active')).toBe(false);
|
||||
expect(element.hasClass('two-active')).toBe(false);
|
||||
|
|
@ -825,8 +767,7 @@ describe("ngAnimate", function() {
|
|||
flag = true;
|
||||
});
|
||||
|
||||
$timeout.flushNext(0); //move operation callback
|
||||
$timeout.flushNext(0); //ngAnimate callback
|
||||
$timeout.flush();
|
||||
|
||||
expect(flag).toBe(true);
|
||||
}));
|
||||
|
|
@ -844,7 +785,8 @@ describe("ngAnimate", function() {
|
|||
flag = true;
|
||||
});
|
||||
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flush();
|
||||
|
||||
expect(flag).toBe(true);
|
||||
}));
|
||||
|
||||
|
|
@ -862,8 +804,7 @@ describe("ngAnimate", function() {
|
|||
flag = true;
|
||||
});
|
||||
|
||||
$timeout.flushNext(0); //move operation callback
|
||||
$timeout.flushNext(0); //ngAnimate callback
|
||||
$timeout.flush();
|
||||
|
||||
expect(flag).toBe(true);
|
||||
expect(element.parent().id).toBe(parent2.id);
|
||||
|
|
@ -881,13 +822,13 @@ describe("ngAnimate", function() {
|
|||
$animate.addClass(element, 'on', function() {
|
||||
signature += 'A';
|
||||
});
|
||||
$timeout.flushNext(0);
|
||||
|
||||
$animate.removeClass(element, 'on', function() {
|
||||
signature += 'B';
|
||||
});
|
||||
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flush();
|
||||
|
||||
expect(signature).toBe('AB');
|
||||
}));
|
||||
|
||||
|
|
@ -904,8 +845,7 @@ describe("ngAnimate", function() {
|
|||
flag = true;
|
||||
});
|
||||
|
||||
var timeoutDelay = $sniffer.transitions ? 1 : 0;
|
||||
$timeout.flush(timeoutDelay);
|
||||
$timeout.flush();
|
||||
expect(flag).toBe(true);
|
||||
}));
|
||||
|
||||
|
|
@ -927,11 +867,7 @@ describe("ngAnimate", function() {
|
|||
flag = true;
|
||||
});
|
||||
|
||||
if($sniffer.transitions) {
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flushNext(1000);
|
||||
}
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flush();
|
||||
expect(flag).toBe(true);
|
||||
}));
|
||||
|
||||
|
|
@ -949,8 +885,7 @@ describe("ngAnimate", function() {
|
|||
flag = true;
|
||||
});
|
||||
|
||||
$timeout.flushNext(2000);
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flush();
|
||||
expect(flag).toBe(true);
|
||||
}));
|
||||
|
||||
|
|
@ -975,19 +910,7 @@ describe("ngAnimate", function() {
|
|||
signature += 'B';
|
||||
});
|
||||
|
||||
if($sniffer.transitions) {
|
||||
$timeout.flushNext(0); //callback for removeClass
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flushNext(9000);
|
||||
$timeout.flushNext(9000);
|
||||
$timeout.flushNext(0);
|
||||
}
|
||||
$animate.addClass(element, 'ng-hide'); //earlier animation cancelled
|
||||
if($sniffer.transitions) {
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flushNext(9000);
|
||||
}
|
||||
$timeout.flush();
|
||||
expect(signature).toBe('AB');
|
||||
}));
|
||||
|
|
@ -1023,12 +946,10 @@ describe("ngAnimate", function() {
|
|||
var element = jqLite(parent.find('span'));
|
||||
|
||||
$animate.addClass(element,'klass');
|
||||
$timeout.flushNext(0);
|
||||
|
||||
expect(element.hasClass('klass')).toBe(true);
|
||||
|
||||
$animate.removeClass(element,'klass');
|
||||
$timeout.flushNext(0);
|
||||
|
||||
expect(element.hasClass('klass')).toBe(false);
|
||||
expect(element.hasClass('klass-remove')).toBe(false);
|
||||
|
|
@ -1049,16 +970,14 @@ describe("ngAnimate", function() {
|
|||
signature += 'A';
|
||||
});
|
||||
|
||||
$timeout.flushNext(0);
|
||||
expect(element.hasClass('klass')).toBe(true);
|
||||
|
||||
$animate.removeClass(element,'klass', function() {
|
||||
signature += 'B';
|
||||
});
|
||||
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flush();
|
||||
expect(element.hasClass('klass')).toBe(false);
|
||||
|
||||
expect(signature).toBe('AB');
|
||||
}));
|
||||
|
||||
|
|
@ -1083,11 +1002,9 @@ describe("ngAnimate", function() {
|
|||
if($sniffer.transitions) {
|
||||
expect(element.hasClass('klass')).toBe(false);
|
||||
expect(element.hasClass('klass-add')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
expect(element.hasClass('klass-add-active')).toBe(true);
|
||||
$timeout.flushNext(3000);
|
||||
}
|
||||
$timeout.flushNext(0);
|
||||
|
||||
//this cancels out the older animation
|
||||
$animate.removeClass(element,'klass', function() {
|
||||
|
|
@ -1099,7 +1016,6 @@ describe("ngAnimate", function() {
|
|||
expect(element.hasClass('klass-add')).toBe(false);
|
||||
expect(element.hasClass('klass-add-active')).toBe(false);
|
||||
|
||||
$timeout.flushNext(0);
|
||||
expect(element.hasClass('klass-remove')).toBe(true);
|
||||
}
|
||||
$timeout.flush();
|
||||
|
|
@ -1122,8 +1038,7 @@ describe("ngAnimate", function() {
|
|||
signature += 'X';
|
||||
});
|
||||
|
||||
$timeout.flushNext(500);
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flush(500);
|
||||
|
||||
expect(element.hasClass('klassy')).toBe(true);
|
||||
|
||||
|
|
@ -1131,8 +1046,7 @@ describe("ngAnimate", function() {
|
|||
signature += 'Y';
|
||||
});
|
||||
|
||||
$timeout.flushNext(3000);
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flush(3000);
|
||||
|
||||
expect(element.hasClass('klassy')).toBe(false);
|
||||
|
||||
|
|
@ -1159,14 +1073,13 @@ describe("ngAnimate", function() {
|
|||
});
|
||||
if($sniffer.transitions) {
|
||||
expect(element.hasClass('klass-add')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
expect(element.hasClass('klass-add-active')).toBe(true);
|
||||
$timeout.flushNext(11000);
|
||||
expect(element.hasClass('klass-add')).toBe(false);
|
||||
expect(element.hasClass('klass-add-active')).toBe(false);
|
||||
}
|
||||
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flush();
|
||||
expect(element.hasClass('klass')).toBe(true);
|
||||
|
||||
$animate.removeClass(element,'klass', function() {
|
||||
|
|
@ -1174,14 +1087,13 @@ describe("ngAnimate", function() {
|
|||
});
|
||||
if($sniffer.transitions) {
|
||||
expect(element.hasClass('klass-remove')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
expect(element.hasClass('klass-remove-active')).toBe(true);
|
||||
$timeout.flushNext(11000);
|
||||
expect(element.hasClass('klass-remove')).toBe(false);
|
||||
expect(element.hasClass('klass-remove-active')).toBe(false);
|
||||
}
|
||||
|
||||
$timeout.flushNext(0);
|
||||
$timeout.flush();
|
||||
expect(element.hasClass('klass')).toBe(false);
|
||||
|
||||
expect(signature).toBe('db');
|
||||
|
|
@ -1208,7 +1120,6 @@ describe("ngAnimate", function() {
|
|||
if($sniffer.transitions) {
|
||||
expect(element.hasClass('one-add')).toBe(true);
|
||||
expect(element.hasClass('two-add')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
|
||||
expect(element.hasClass('one-add-active')).toBe(true);
|
||||
expect(element.hasClass('two-add-active')).toBe(true);
|
||||
|
|
@ -1219,7 +1130,8 @@ describe("ngAnimate", function() {
|
|||
expect(element.hasClass('two-add')).toBe(false);
|
||||
expect(element.hasClass('two-add-active')).toBe(false);
|
||||
}
|
||||
$timeout.flushNext(0);
|
||||
|
||||
$timeout.flush();
|
||||
|
||||
expect(element.hasClass('one')).toBe(true);
|
||||
expect(element.hasClass('two')).toBe(true);
|
||||
|
|
@ -1228,7 +1140,7 @@ describe("ngAnimate", function() {
|
|||
}));
|
||||
|
||||
it("should allow for multiple css classes to be animated plus a callback when removed",
|
||||
inject(function($animate, $rootScope, $sniffer, $rootElement, $timeout) {
|
||||
inject(function($animate, $rootScope, $sniffer, $rootElement, $timeout, filterFilter) {
|
||||
|
||||
ss.addRule('.one-remove', 'transition:9s linear all;' +
|
||||
vendorPrefix + 'transition:9s linear all');
|
||||
|
|
@ -1252,7 +1164,6 @@ describe("ngAnimate", function() {
|
|||
if($sniffer.transitions) {
|
||||
expect(element.hasClass('one-remove')).toBe(true);
|
||||
expect(element.hasClass('two-remove')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
|
||||
expect(element.hasClass('one-remove-active')).toBe(true);
|
||||
expect(element.hasClass('two-remove-active')).toBe(true);
|
||||
|
|
@ -1263,7 +1174,8 @@ describe("ngAnimate", function() {
|
|||
expect(element.hasClass('two-remove')).toBe(false);
|
||||
expect(element.hasClass('two-remove-active')).toBe(false);
|
||||
}
|
||||
$timeout.flushNext(0);
|
||||
|
||||
$timeout.flush();
|
||||
|
||||
expect(element.hasClass('one')).toBe(false);
|
||||
expect(element.hasClass('two')).toBe(false);
|
||||
|
|
@ -1300,11 +1212,9 @@ describe("ngAnimate", function() {
|
|||
var child = $compile('<div>...</div>')($rootScope);
|
||||
|
||||
$animate.enter(child, element);
|
||||
$timeout.flushNext(0);
|
||||
|
||||
if($sniffer.transitions) {
|
||||
expect(child.hasClass('ng-enter')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
expect(child.hasClass('ng-enter-active')).toBe(true);
|
||||
$timeout.flushNext(1000);
|
||||
}
|
||||
|
|
@ -1323,11 +1233,9 @@ describe("ngAnimate", function() {
|
|||
var child = $compile('<div>...</div>')($rootScope);
|
||||
|
||||
$animate.enter(child, element);
|
||||
$timeout.flushNext(0);
|
||||
|
||||
if($sniffer.transitions) {
|
||||
expect(child.hasClass('ng-enter')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
expect(child.hasClass('ng-enter-active')).toBe(true);
|
||||
$timeout.flushNext(9000);
|
||||
}
|
||||
|
|
@ -1375,21 +1283,11 @@ describe("ngAnimate", function() {
|
|||
|
||||
child.addClass('custom');
|
||||
$animate.enter(child, element);
|
||||
$timeout.flushNext(0);
|
||||
|
||||
if($sniffer.transitions) {
|
||||
expect(child.hasClass('ng-enter')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
expect(child.hasClass('ng-enter-active')).toBe(true);
|
||||
}
|
||||
|
||||
$timeout.flushNext(10);
|
||||
|
||||
if($sniffer.transitions) {
|
||||
expect(child.hasClass('ng-enter-active')).toBe(true);
|
||||
$timeout.flushNext(1000);
|
||||
expect(child.hasClass('ng-enter')).toBe(false);
|
||||
expect(child.hasClass('ng-enter-active')).toBe(false);
|
||||
}
|
||||
|
||||
expect(child.hasClass('i-was-animated')).toBe(true);
|
||||
|
|
@ -1417,38 +1315,24 @@ describe("ngAnimate", function() {
|
|||
var child = $compile('<div>...</div>')($rootScope);
|
||||
|
||||
$animate.enter(child, element);
|
||||
$timeout.flushNext(0);
|
||||
|
||||
//this is added/removed right away otherwise
|
||||
if($sniffer.transitions) {
|
||||
expect(child.hasClass('ng-enter')).toBe(true);
|
||||
$timeout.flushNext(0);
|
||||
expect(child.hasClass('ng-enter-active')).toBe(true);
|
||||
}
|
||||
|
||||
expect(child.hasClass('this-is-mine-now')).toBe(false);
|
||||
child.addClass('usurper');
|
||||
$animate.leave(child);
|
||||
$timeout.flushNext(0);
|
||||
|
||||
expect(child.hasClass('ng-enter')).toBe(false);
|
||||
expect(child.hasClass('ng-enter-active')).toBe(false);
|
||||
|
||||
expect(child.hasClass('usurper')).toBe(true);
|
||||
expect(child.hasClass('this-is-mine-now')).toBe(true);
|
||||
if($sniffer.transitions) {
|
||||
$timeout.flushNext(0);
|
||||
}
|
||||
|
||||
$timeout.flushNext(55);
|
||||
if($sniffer.transitions) {
|
||||
$timeout.flushNext(2000);
|
||||
|
||||
//even though this exists, the animation will still not happen
|
||||
//since the done function has already been called in the cancellation
|
||||
$timeout.flushNext(2000);
|
||||
}
|
||||
|
||||
expect(child.hasClass('usurper-active')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -1572,15 +1456,12 @@ describe("ngAnimate", function() {
|
|||
|
||||
$animate.addClass(element, 'super');
|
||||
expect(element.data('classify')).toBe('add-super');
|
||||
$timeout.flush();
|
||||
|
||||
$animate.removeClass(element, 'super');
|
||||
expect(element.data('classify')).toBe('remove-super');
|
||||
$timeout.flush();
|
||||
|
||||
$animate.addClass(element, 'superguy');
|
||||
expect(element.data('classify')).toBe('add-superguy');
|
||||
$timeout.flush();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -1600,7 +1481,6 @@ describe("ngAnimate", function() {
|
|||
jqLite(document.body).append($rootElement);
|
||||
|
||||
$animate.addClass(element, 'super');
|
||||
$timeout.flush(0);
|
||||
|
||||
var empty = true;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -628,32 +628,22 @@ describe('ngView animations', function() {
|
|||
$rootScope.$digest();
|
||||
|
||||
$animate.flushNext('enter'); //ngView
|
||||
|
||||
$timeout.flush();
|
||||
|
||||
$animate.flushNext('enter'); //repeat 1
|
||||
$animate.flushNext('enter'); //repeat 2
|
||||
|
||||
$timeout.flush();
|
||||
|
||||
expect(element.text()).toEqual('12');
|
||||
|
||||
$location.path('/bar');
|
||||
$rootScope.$digest();
|
||||
|
||||
$animate.flushNext('leave'); //ngView old
|
||||
$timeout.flush();
|
||||
|
||||
$animate.flushNext('enter'); //ngView new
|
||||
$timeout.flush();
|
||||
|
||||
expect(n(element.text())).toEqual(''); //this is midway during the animation
|
||||
|
||||
$animate.flushNext('enter'); //ngRepeat 3
|
||||
$animate.flushNext('enter'); //ngRepeat 4
|
||||
|
||||
$timeout.flush();
|
||||
|
||||
expect(element.text()).toEqual('34');
|
||||
|
||||
function n(text) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue