22
33describe ( "$animator" , function ( ) {
44
5- var element ;
5+ var body , element ;
6+
7+ function html ( html ) {
8+ body . html ( html ) ;
9+ element = body . children ( ) . eq ( 0 ) ;
10+ return element ;
11+ }
12+
13+ beforeEach ( function ( ) {
14+ // we need to run animation on attached elements;
15+ body = jqLite ( document . body ) ;
16+ } ) ;
617
718 afterEach ( function ( ) {
8- dealoc ( element ) ;
19+ dealoc ( body ) ;
920 } ) ;
1021
1122 describe ( "enable / disable" , function ( ) {
@@ -120,6 +131,7 @@ describe("$animator", function() {
120131 animator = $animator ( $rootScope , {
121132 ngAnimate : '{enter: \'custom\'}'
122133 } ) ;
134+ $rootScope . $digest ( ) ; // re-enable the animations;
123135 expect ( element . contents ( ) . length ) . toBe ( 0 ) ;
124136 animator . enter ( child , element ) ;
125137 window . setTimeout . expect ( 1 ) . process ( ) ;
@@ -129,6 +141,7 @@ describe("$animator", function() {
129141 animator = $animator ( $rootScope , {
130142 ngAnimate : '{leave: \'custom\'}'
131143 } ) ;
144+ $rootScope . $digest ( ) ;
132145 element . append ( child ) ;
133146 expect ( element . contents ( ) . length ) . toBe ( 1 ) ;
134147 animator . leave ( child , element ) ;
@@ -140,6 +153,7 @@ describe("$animator", function() {
140153 animator = $animator ( $rootScope , {
141154 ngAnimate : '{move: \'custom\'}'
142155 } ) ;
156+ $rootScope . $digest ( ) ;
143157 var child1 = $compile ( '<div>1</div>' ) ( $rootScope ) ;
144158 var child2 = $compile ( '<div>2</div>' ) ( $rootScope ) ;
145159 element . append ( child1 ) ;
@@ -154,6 +168,7 @@ describe("$animator", function() {
154168 animator = $animator ( $rootScope , {
155169 ngAnimate : '{show: \'custom\'}'
156170 } ) ;
171+ $rootScope . $digest ( ) ;
157172 element . css ( 'display' , 'none' ) ;
158173 expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
159174 animator . show ( element ) ;
@@ -166,6 +181,7 @@ describe("$animator", function() {
166181 animator = $animator ( $rootScope , {
167182 ngAnimate : '{hide: \'custom\'}'
168183 } ) ;
184+ $rootScope . $digest ( ) ;
169185 element . css ( 'display' , 'block' ) ;
170186 expect ( element . css ( 'display' ) ) . toBe ( 'block' ) ;
171187 animator . hide ( element ) ;
@@ -181,6 +197,8 @@ describe("$animator", function() {
181197 ngAnimate : '"custom"'
182198 } ) ;
183199
200+ $rootScope . $digest ( ) ;
201+
184202 //enter
185203 animator . enter ( child , element ) ;
186204 expect ( child . attr ( 'class' ) ) . toContain ( 'custom-enter-setup' ) ;
@@ -222,6 +240,7 @@ describe("$animator", function() {
222240 animator = $animator ( $rootScope , {
223241 ngAnimate : '{show: \'setup-memo\'}'
224242 } ) ;
243+ $rootScope . $digest ( ) ;
225244 expect ( element . text ( ) ) . toEqual ( '' ) ;
226245 animator . show ( element ) ;
227246 window . setTimeout . expect ( 1 ) . process ( ) ;
@@ -234,6 +253,8 @@ describe("$animator", function() {
234253 animator = $animator ( $rootScope , {
235254 ngAnimate : '{show: \'setup-memo\'}'
236255 } ) ;
256+ $rootScope . $digest ( ) ;
257+
237258 element . text ( '123' ) ;
238259 expect ( element . text ( ) ) . toBe ( '123' ) ;
239260 animator . show ( element ) ;
@@ -262,11 +283,13 @@ describe("$animator", function() {
262283 it ( "should skip animations if disabled and run when enabled" ,
263284 inject ( function ( $animator , $rootScope , $compile , $sniffer ) {
264285 $animator . enabled ( false ) ;
265- element = $compile ( '<div style="transition: 1s linear all">1</div>' ) ( $rootScope ) ;
286+ element = $compile ( html ( '<div style="' + vendorPrefix + ' transition: 1s linear all">1</div>') ) ( $rootScope ) ;
266287 var animator = $animator ( $rootScope , {
267288 ngAnimate : '{show: \'inline-show\'}'
268289 } ) ;
269290
291+ $rootScope . $digest ( ) ; // skip no-animate on first digest.
292+
270293 element . css ( 'display' , 'none' ) ;
271294 expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
272295 animator . show ( element ) ;
@@ -289,6 +312,7 @@ describe("$animator", function() {
289312 it ( "should throw an error when an invalid ng-animate syntax is provided" , inject ( function ( $compile , $rootScope ) {
290313 expect ( function ( ) {
291314 element = $compile ( '<div ng-repeat="i in is" ng-animate=":"></div>' ) ( $rootScope ) ;
315+ $rootScope . $digest ( ) ;
292316 } ) . toThrow ( "Syntax Error: Token ':' not a primary expression at column 1 of the expression [:] starting at [:]." ) ;
293317 } ) ) ;
294318} ) ;
0 commit comments