diff options
| author | Matias Niemelä | 2014-02-26 22:37:03 -0500 | 
|---|---|---|
| committer | Matias Niemelä | 2014-02-28 01:34:57 -0500 | 
| commit | 18c41af065006a804a3d38eecca7ae184103ece9 (patch) | |
| tree | 866dd8d44478df36147aac844c89388a96152eb0 /test/ngAnimate/animateSpec.js | |
| parent | 33443966c8e8cac85a863bb181d4a4aff00baab4 (diff) | |
| download | angular.js-18c41af065006a804a3d38eecca7ae184103ece9.tar.bz2 | |
fix($animate): delegate down to addClass/removeClass if setClass is not found
Closes #6463
Diffstat (limited to 'test/ngAnimate/animateSpec.js')
| -rw-r--r-- | test/ngAnimate/animateSpec.js | 99 | 
1 files changed, 99 insertions, 0 deletions
| diff --git a/test/ngAnimate/animateSpec.js b/test/ngAnimate/animateSpec.js index 6dd3b117..fb9ba19e 100644 --- a/test/ngAnimate/animateSpec.js +++ b/test/ngAnimate/animateSpec.js @@ -364,6 +364,82 @@ describe("ngAnimate", function() {          })); +        it("should exclusively animate the setClass animation event", function() { +          var count = 0, fallback = jasmine.createSpy('callback'); +          module(function($animateProvider) { +            $animateProvider.register('.classify', function() { +              return { +                beforeAddClass : fallback, +                addClass : fallback, +                beforeRemoveClass : fallback, +                removeClass : fallback, + +                beforeSetClass : function(element, add, remove, done) { +                  count++; +                  expect(add).toBe('yes'); +                  expect(remove).toBe('no'); +                  done(); +                }, +                setClass : function(element, add, remove, done) { +                  count++; +                  expect(add).toBe('yes'); +                  expect(remove).toBe('no'); +                  done(); +                } +              }; +            }); +          }) +          inject(function($animate, $rootScope, $sniffer, $timeout) { +            child.attr('class','classify no'); +            $animate.setClass(child, 'yes', 'no'); + +            expect(child.hasClass('yes')).toBe(true); +            expect(child.hasClass('no')).toBe(false); +            expect(count).toBe(2); + +            expect(fallback).not.toHaveBeenCalled(); +          }); +        }); + + +        it("should delegate down to addClass/removeClass if a setClass animation is not found", function() { +          var count = 0; +          module(function($animateProvider) { +            $animateProvider.register('.classify', function() { +              return { +                beforeAddClass : function(element, className, done) { +                  count++; +                  expect(className).toBe('yes'); +                  done(); +                }, +                addClass : function(element, className, done) { +                  count++; +                  expect(className).toBe('yes'); +                  done(); +                }, +                beforeRemoveClass : function(element, className, done) { +                  count++; +                  expect(className).toBe('no'); +                  done(); +                }, +                removeClass : function(element, className, done) { +                  count++; +                  expect(className).toBe('no'); +                  done(); +                } +              }; +            }); +          }) +          inject(function($animate, $rootScope, $sniffer, $timeout) { +            child.attr('class','classify no'); +            $animate.setClass(child, 'yes', 'no'); + +            expect(child.hasClass('yes')).toBe(true); +            expect(child.hasClass('no')).toBe(false); +            expect(count).toBe(4); +          }); +        }); +          it("should assign the ng-event className to all animation events when transitions/keyframes are used",            inject(function($animate, $sniffer, $rootScope, $timeout) { @@ -1584,6 +1660,29 @@ describe("ngAnimate", function() {            expect(signature).toBe('AB');          })); +        it("should fire the setClass callback", +          inject(function($animate, $rootScope, $compile, $sniffer, $rootElement, $timeout) { + +          var parent = jqLite('<div><span class="off"></span></div>'); +          var element = parent.find('span'); +          $rootElement.append(parent); +          body.append($rootElement); + +          expect(element.hasClass('on')).toBe(false); +          expect(element.hasClass('off')).toBe(true); + +          var signature = ''; +          $animate.setClass(element, 'on', 'off', function() { +            signature += 'Z'; +          }); + +          $animate.triggerCallbacks(); + +          expect(signature).toBe('Z'); +          expect(element.hasClass('on')).toBe(true); +          expect(element.hasClass('off')).toBe(false); +        })); +          it('should fire DOM callbacks on the element being animated',            inject(function($animate, $rootScope, $compile, $sniffer, $rootElement, $timeout) { | 
