@@ -1912,33 +1912,62 @@ describe("animations", function() {
1912
1912
expect ( capturedElement ) . toBe ( element ) ;
1913
1913
} ) ) ;
1914
1914
1915
- it ( 'should remove the event listener if the element is removed' ,
1915
+ it ( 'should remove all event listeners when the element is removed' ,
1916
1916
inject ( function ( $animate , $rootScope , $rootElement ) {
1917
1917
1918
1918
element = jqLite ( '<div></div>' ) ;
1919
1919
1920
1920
var count = 0 ;
1921
+ var runner ;
1922
+
1921
1923
$animate . on ( 'enter' , element , counter ) ;
1922
- $animate . on ( 'addClass' , element , counter ) ;
1924
+ $animate . on ( 'addClass' , element [ 0 ] , counter ) ;
1923
1925
1924
1926
function counter ( element , phase ) {
1925
1927
if ( phase === 'start' ) {
1926
1928
count ++ ;
1927
1929
}
1928
1930
}
1929
1931
1930
- $animate . enter ( element , $rootElement ) ;
1932
+ runner = $animate . enter ( element , $rootElement ) ;
1931
1933
$rootScope . $digest ( ) ;
1932
- $animate . flush ( ) ;
1934
+ expect ( capturedAnimation ) . toBeTruthy ( ) ;
1933
1935
1936
+ $animate . flush ( ) ;
1937
+ runner . end ( ) ; // Otherwise the class animation won't run because enter is still in progress
1934
1938
expect ( count ) . toBe ( 1 ) ;
1939
+
1940
+ capturedAnimation = null ;
1941
+
1942
+ $animate . addClass ( element , 'blue' ) ;
1943
+ $rootScope . $digest ( ) ;
1944
+ expect ( capturedAnimation ) . toBeTruthy ( ) ;
1945
+
1946
+ $animate . flush ( ) ;
1947
+ expect ( count ) . toBe ( 2 ) ;
1948
+
1949
+ capturedAnimation = null ;
1950
+
1935
1951
element . remove ( ) ;
1936
1952
1937
- $animate . addClass ( element , 'viljami' ) ;
1953
+ runner = $animate . enter ( element , $rootElement ) ;
1938
1954
$rootScope . $digest ( ) ;
1939
1955
1956
+ expect ( capturedAnimation ) . toBeTruthy ( ) ;
1957
+
1940
1958
$animate . flush ( ) ;
1941
- expect ( count ) . toBe ( 1 ) ;
1959
+ runner . end ( ) ; // Otherwise the class animation won't run because enter is still in progress
1960
+
1961
+ expect ( count ) . toBe ( 2 ) ;
1962
+
1963
+ capturedAnimation = null ;
1964
+
1965
+ $animate . addClass ( element , 'red' ) ;
1966
+ $rootScope . $digest ( ) ;
1967
+ expect ( capturedAnimation ) . toBeTruthy ( ) ;
1968
+
1969
+ $animate . flush ( ) ;
1970
+ expect ( count ) . toBe ( 2 ) ;
1942
1971
} ) ) ;
1943
1972
1944
1973
it ( 'should always detect registered callbacks after one postDigest has fired' ,
@@ -2116,7 +2145,6 @@ describe("animations", function() {
2116
2145
2117
2146
var callbackTriggered = false ;
2118
2147
2119
-
2120
2148
$animate . on ( $event , $document [ 0 ] , function ( ) {
2121
2149
callbackTriggered = true ;
2122
2150
} ) ;
0 commit comments