@@ -1896,6 +1896,68 @@ describe("animations", function() {
1896
1896
expect ( count ) . toBe ( 3 ) ;
1897
1897
} ) ) ;
1898
1898
1899
+ it ( 'should remove all event listeners for an element when $animate.off(element) is called' ,
1900
+ inject ( function ( $animate , $rootScope , $rootElement , $document , $$rAF ) {
1901
+
1902
+ element = jqLite ( '<div></div>' ) ;
1903
+ var otherElement = jqLite ( '<div></div>' ) ;
1904
+ $rootElement . append ( otherElement ) ;
1905
+
1906
+ var count = 0 ;
1907
+ var runner ;
1908
+ $animate . on ( 'enter' , element , counter ) ;
1909
+ $animate . on ( 'leave' , element , counter ) ;
1910
+ $animate . on ( 'addClass' , element , counter ) ;
1911
+ $animate . on ( 'addClass' , otherElement , counter ) ;
1912
+
1913
+ function counter ( element , phase ) {
1914
+ count ++ ;
1915
+ }
1916
+
1917
+ runner = $animate . enter ( element , $rootElement ) ;
1918
+ $rootScope . $digest ( ) ;
1919
+ $animate . flush ( ) ;
1920
+ runner . end ( ) ;
1921
+
1922
+ runner = $animate . addClass ( element , 'blue' ) ;
1923
+ $rootScope . $digest ( ) ;
1924
+ $animate . flush ( ) ;
1925
+
1926
+ runner . end ( ) ;
1927
+ $$rAF . flush ( ) ;
1928
+
1929
+ expect ( count ) . toBe ( 4 ) ;
1930
+
1931
+ $animate . off ( element ) ;
1932
+
1933
+ runner = $animate . enter ( element , $rootElement ) ;
1934
+ $animate . flush ( ) ;
1935
+ expect ( capturedAnimation [ 1 ] ) . toBe ( 'enter' ) ;
1936
+ runner . end ( ) ;
1937
+
1938
+ runner = $animate . addClass ( element , 'red' ) ;
1939
+ $animate . flush ( ) ;
1940
+ expect ( capturedAnimation [ 1 ] ) . toBe ( 'addClass' ) ;
1941
+ runner . end ( ) ;
1942
+
1943
+ runner = $animate . leave ( element ) ;
1944
+ $animate . flush ( ) ;
1945
+ expect ( capturedAnimation [ 1 ] ) . toBe ( 'leave' ) ;
1946
+ runner . end ( ) ;
1947
+
1948
+ // Try to flush all remaining callbacks
1949
+ expect ( function ( ) {
1950
+ $$rAF . flush ( ) ;
1951
+ } ) . toThrowError ( 'No rAF callbacks present' ) ;
1952
+
1953
+ expect ( count ) . toBe ( 4 ) ;
1954
+
1955
+ // Check that other elements' event listeners are not affected
1956
+ $animate . addClass ( otherElement , 'green' ) ;
1957
+ $animate . flush ( ) ;
1958
+ expect ( count ) . toBe ( 5 ) ;
1959
+ } ) ) ;
1960
+
1899
1961
it ( 'should fire a `start` callback when the animation starts with the matching element' ,
1900
1962
inject ( function ( $animate , $rootScope , $rootElement , $document ) {
1901
1963
0 commit comments