From dde1b2949727c297e214c99960141bfad438d7a4 Mon Sep 17 00:00:00 2001 From: Matias Niemelä Date: Mon, 13 Jan 2014 21:51:08 -0500 Subject: feat($animate): provide support for DOM callbacks --- test/ngAnimate/animateSpec.js | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'test') diff --git a/test/ngAnimate/animateSpec.js b/test/ngAnimate/animateSpec.js index 1477bca0..6d9367bd 100644 --- a/test/ngAnimate/animateSpec.js +++ b/test/ngAnimate/animateSpec.js @@ -1496,6 +1496,68 @@ describe("ngAnimate", function() { expect(signature).toBe('AB'); })); + it('should fire DOM callbacks on the element being animated', + inject(function($animate, $rootScope, $compile, $sniffer, $rootElement, $timeout) { + + if(!$sniffer.transitions) return; + + $animate.enabled(true); + + ss.addRule('.klass-add', '-webkit-transition:1s linear all;' + + 'transition:1s linear all;'); + + var element = jqLite('
'); + $rootElement.append(element); + body.append($rootElement); + + var steps = []; + element.on('$animate:before', function(e, data) { + steps.push(['before', data.className, data.event]); + }); + + element.on('$animate:after', function(e, data) { + steps.push(['after', data.className, data.event]); + }); + + $animate.addClass(element, 'klass'); + + $timeout.flush(1); + + expect(steps.pop()).toEqual(['before', 'klass', 'addClass']); + + $animate.triggerReflow(); + $timeout.flush(1); + + expect(steps.pop()).toEqual(['after', 'klass', 'addClass']); + })); + + it('should fire the DOM callbacks even if no animation is rendered', + inject(function($animate, $rootScope, $compile, $sniffer, $rootElement, $timeout) { + + $animate.enabled(true); + + var parent = jqLite(''); + var element = jqLite(''); + $rootElement.append(parent); + body.append($rootElement); + + var steps = []; + element.on('$animate:before', function(e, data) { + steps.push(['before', data.className, data.event]); + }); + + element.on('$animate:after', function(e, data) { + steps.push(['after', data.className, data.event]); + }); + + $animate.enter(element, parent); + $rootScope.$digest(); + + $timeout.flush(1); + + expect(steps.shift()).toEqual(['before', 'ng-enter', 'enter']); + expect(steps.shift()).toEqual(['after', 'ng-enter', 'enter']); + })); it("should fire a done callback when provided with no animation", inject(function($animate, $rootScope, $compile, $sniffer, $rootElement, $timeout) { -- cgit v1.2.3