| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
 | 'use strict';
describe("$animator", function() {
  var body, element, $rootElement;
  function html(html) {
    body.append($rootElement);
    $rootElement.html(html);
    element = $rootElement.children().eq(0);
    return element;
  }
  beforeEach(function() {
    // we need to run animation on attached elements;
    body = jqLite(document.body);
  });
  afterEach(function(){
    dealoc(body);
  });
  describe("enable / disable", function() {
    beforeEach(function() {
      module(function($animationProvider, $provide) {
        $provide.value('$window', angular.mock.createMockWindow());
      });
    });
    it("should disable and enable the animations", function() {
      var initialState = null;
      var animator;
      angular.bootstrap(body, [function() {
        return function($animator) {
          animator = $animator;
          initialState = $animator.enabled();
        }
      }]);
      expect(initialState).toBe(false);
      expect(animator.enabled()).toBe(true);
      expect(animator.enabled(0)).toBe(false);
      expect(animator.enabled()).toBe(false);
      expect(animator.enabled(1)).toBe(true);
      expect(animator.enabled()).toBe(true);
    });
  });
  describe("without animation", function() {
    var window, animator;
    beforeEach(function() {
      module(function($animationProvider, $provide) {
        $provide.value('$window', window = angular.mock.createMockWindow());
      })
      inject(function($animator, $compile, $rootScope, _$rootElement_) {
        animator = $animator($rootScope, {});
        element = $compile('<div></div>')($rootScope);
        $rootElement = _$rootElement_;
      })
    });
    it("should add element at the start of enter animation", inject(function($animator, $compile, $rootScope) {
      var child = $compile('<div></div>')($rootScope);
      expect(element.contents().length).toBe(0);
      animator.enter(child, element);
      expect(element.contents().length).toBe(1);
    }));
    it("should remove the element at the end of leave animation", inject(function($animator, $compile, $rootScope) {
      var child = $compile('<div></div>')($rootScope);
      element.append(child);
      expect(element.contents().length).toBe(1);
      animator.leave(child, element);
      expect(element.contents().length).toBe(0);
    }));
    it("should reorder the move animation", inject(function($animator, $compile, $rootScope) {
      var child1 = $compile('<div>1</div>')($rootScope);
      var child2 = $compile('<div>2</div>')($rootScope);
      element.append(child1);
      element.append(child2);
      expect(element.text()).toBe('12');
      animator.move(child1, element, child2);
      expect(element.text()).toBe('21');
    }));
    it("should animate the show animation event", inject(function() {
      element.css('display','none');
      expect(element.css('display')).toBe('none');
      animator.show(element);
      expect(element[0].style.display).toBe('');
    }));
    it("should animate the hide animation event", inject(function() {
      element.css('display','block');
      expect(element.css('display')).toBe('block');
      animator.hide(element);
      expect(element.css('display')).toBe('none');
    }));
    it("should still perform DOM operations even if animations are disabled", inject(function($animator) {
      $animator.enabled(false);
      element.css('display','block');
      expect(element.css('display')).toBe('block');
      animator.hide(element);
      expect(element.css('display')).toBe('none');
    }));
  });
  describe("with polyfill", function() {
    var child, after, window, animator;
    beforeEach(function() {
      module(function($animationProvider, $provide) {
        $provide.value('$window', window = angular.mock.createMockWindow());
        $animationProvider.register('custom', function() {
          return {
            start: function(element, done) {
              done();
            }
          }
        });
       $animationProvider.register('custom-delay', function() {
          return {
            start: function(element, done) {
              window.setTimeout(done, 2000);
            },
            cancel : function(element) {
              element.addClass('animation-cancelled');
            }
          }
        });
       $animationProvider.register('setup-memo', function() {
          return {
            setup: function(element) {
              return "memento";
            },
            start: function(element, done, memento) {
              element.text(memento);
              done();
            }
          }
        });
      })
      inject(function($animator, $compile, $rootScope, $rootElement) {
        element = $compile('<div></div>')($rootScope);
        child   = $compile('<div></div>')($rootScope);
        after   = $compile('<div></div>')($rootScope);
        $rootElement.append(element);
      });
    })
    it("should animate the enter animation event", inject(function($animator, $rootScope) {
      $animator.enabled(true);
      animator = $animator($rootScope, {
        ngAnimate : '{enter: \'custom\'}'
      });
      expect(element.contents().length).toBe(0);
      animator.enter(child, element);
      window.setTimeout.expect(1).process();
    }));
    it("should animate the leave animation event", inject(function($animator, $rootScope) {
      $animator.enabled(true);
      animator = $animator($rootScope, {
        ngAnimate : '{leave: \'custom\'}'
      });
      element.append(child);
      expect(element.contents().length).toBe(1);
      animator.leave(child, element);
      window.setTimeout.expect(1).process();
      expect(element.contents().length).toBe(0);
    }));
    it("should animate the move animation event", inject(function($animator, $compile, $rootScope) {
      $animator.enabled(true);
      animator = $animator($rootScope, {
        ngAnimate : '{move: \'custom\'}'
      });
      $rootScope.$digest();
      var child1 = $compile('<div>1</div>')($rootScope);
      var child2 = $compile('<div>2</div>')($rootScope);
      element.append(child1);
      element.append(child2);
      expect(element.text()).toBe('12');
      animator.move(child1, element, child2);
      expect(element.text()).toBe('21');
      window.setTimeout.expect(1).process();
    }));
    it("should animate the show animation event", inject(function($animator, $rootScope) {
      $animator.enabled(true);
      animator = $animator($rootScope, {
        ngAnimate : '{show: \'custom\'}'
      });
      $rootScope.$digest();
      element.css('display','none');
      expect(element.css('display')).toBe('none');
      animator.show(element);
      expect(element[0].style.display).toBe('');
      window.setTimeout.expect(1).process();
      expect(element[0].style.display).toBe('');
    }));
    it("should animate the hide animation event", inject(function($animator, $rootScope) {
      $animator.enabled(true);
      animator = $animator($rootScope, {
        ngAnimate : '{hide: \'custom\'}'
      });
      $rootScope.$digest();
      element.css('display','block');
      expect(element.css('display')).toBe('block');
      animator.hide(element);
      expect(element.css('display')).toBe('block');
      window.setTimeout.expect(1).process();
      expect(element.css('display')).toBe('none');
    }));
    it("should assign the ngAnimate string to all events if a string is given",
        inject(function($animator, $sniffer, $rootScope) {
      $animator.enabled(true);
      if (!$sniffer.transitions) return;
      animator = $animator($rootScope, {
        ngAnimate : '"custom"'
      });
      $rootScope.$digest();
      //enter
      animator.enter(child, element);
      expect(child.attr('class')).toContain('custom-enter');
      window.setTimeout.expect(1).process();
      expect(child.attr('class')).toContain('custom-enter-active');
      window.setTimeout.expect(0).process();
      //leave
      element.append(after);
      animator.move(child, element, after);
      expect(child.attr('class')).toContain('custom-move');
      window.setTimeout.expect(1).process();
      expect(child.attr('class')).toContain('custom-move-active');
      window.setTimeout.expect(0).process();
      //hide
      animator.hide(child);
      expect(child.attr('class')).toContain('custom-hide');
      window.setTimeout.expect(1).process();
      expect(child.attr('class')).toContain('custom-hide-active');
      window.setTimeout.expect(0).process();
      //show
      animator.show(child);
      expect(child.attr('class')).toContain('custom-show');
      window.setTimeout.expect(1).process();
      expect(child.attr('class')).toContain('custom-show-active');
      window.setTimeout.expect(0).process();
      //leave
      animator.leave(child);
      expect(child.attr('class')).toContain('custom-leave');
      window.setTimeout.expect(1).process();
      expect(child.attr('class')).toContain('custom-leave-active');
      window.setTimeout.expect(0).process();
    }));
    it("should run polyfillSetup and return the memento", inject(function($animator, $rootScope) {
      $animator.enabled(true);
      animator = $animator($rootScope, {
        ngAnimate : '{show: \'setup-memo\'}'
      });
      $rootScope.$digest();
      expect(element.text()).toEqual('');
      animator.show(element);
      window.setTimeout.expect(1).process();
      expect(element.text()).toBe('memento');
    }));
    it("should not run if animations are disabled", inject(function($animator, $rootScope) {
      $animator.enabled(false);
      animator = $animator($rootScope, {
        ngAnimate : '{show: \'setup-memo\'}'
      });
      $rootScope.$digest();
      element.text('123');
      expect(element.text()).toBe('123');
      animator.show(element);
      expect(element.text()).toBe('123');
      $animator.enabled(true);
      animator.show(element);
      window.setTimeout.expect(1).process();
      expect(element.text()).toBe('memento');
    }));
    it("should only call done() once and right away if another animation takes place in between",
      inject(function($animator, $rootScope) {
      $animator.enabled(true);
      animator = $animator($rootScope, {
        ngAnimate : '{hide: \'custom-delay\', leave: \'custom-delay\'}'
      });
      element.append(child);
      child.css('display','block');
      animator.hide(child);
      window.setTimeout.expect(1).process();
      expect(child.css('display')).toBe('block');
      animator.leave(child);
      expect(child.css('display')).toBe('none'); //hides instantly
      //lets change this to prove that done doesn't fire anymore for the previous hide() operation
      child.css('display','block'); 
      window.setTimeout.expect(2000).process();
      expect(child.css('display')).toBe('block'); //doesn't run the done() method to hide it
      expect(element.children().length).toBe(1); //still animating
      window.setTimeout.expect(1).process();
      window.setTimeout.expect(2000).process();
      expect(element.children().length).toBe(0);
    }));
    it("should call the cancel callback when another animation is called on the same element",
      inject(function($animator, $rootScope) {
      $animator.enabled(true);
      animator = $animator($rootScope, {
        ngAnimate : '{hide: \'custom-delay\', show: \'custom-delay\'}'
      });
      child.css('display','none');
      element.data('foo', 'bar');
      animator.show(element);
      window.setTimeout.expect(1).process();
      animator.hide(element);
      expect(element.hasClass('animation-cancelled')).toBe(true);
      expect(element.data('foo')).toEqual('bar');
    }));
    it("should NOT clobber all data on an element when animation is finished",
      inject(function($animator, $rootScope) {
      $animator.enabled(true);
      animator = $animator($rootScope, {
        ngAnimate : '{hide: \'custom-delay\', show: \'custom-delay\'}'
      });
      child.css('display','none');
      element.data('foo', 'bar');
      animator.show(element);
      window.setTimeout.expect(1).process();
      animator.hide(element);
      expect(element.data('foo')).toEqual('bar');
    }));
    it("should properly animate custom animation events", inject(function($animator, $rootScope) {
      $animator.enabled(true);
      animator = $animator($rootScope, {
        ngAnimate : '{custom: \'setup-memo\'}'
      });
      element.text('123');
      animator.animate('custom',element);
      window.setTimeout.expect(1).process();
      expect(element.text()).toBe('memento');
    }));
  });
  describe("with CSS3", function() {
    var window, animator, prefix, vendorPrefix;
    beforeEach(function() {
      module(function($animationProvider, $provide) {
        $provide.value('$window', window = angular.mock.createMockWindow());
        return function($sniffer, _$rootElement_, $animator) {
          vendorPrefix = '-' + $sniffer.vendorPrefix.toLowerCase() + '-';
          $rootElement = _$rootElement_;
          $animator.enabled(true);
        };
      })
    });
    it("should properly animate custom animations for specific animation events",
      inject(function($animator, $rootScope, $compile, $sniffer) {
      $animator.enabled(true);
      var element = $compile(html('<div></div>'))($rootScope);
      animator = $animator($rootScope, {
        ngAnimate : '{custom: \'special\'}'
      });
      animator.animate('custom',element);
      if($sniffer.transitions) {
        expect(element.hasClass('special')).toBe(true);
        window.setTimeout.expect(1).process();
        expect(element.hasClass('special-active')).toBe(true);
      }
      else {
        expect(window.setTimeout.queue.length).toBe(0);
      }
    }));
    it("should not animate custom animations if not specifically defined",
      inject(function($animator, $rootScope, $compile) {
      $animator.enabled(true);
      var element = $compile(html('<div></div>'))($rootScope);
      animator = $animator($rootScope, {
        ngAnimate : '{custom: \'special\'}'
      });
      expect(window.setTimeout.queue.length).toBe(0);
      animator.animate('custom1',element);
      expect(element.hasClass('special')).toBe(false);
      expect(window.setTimeout.queue.length).toBe(0);
    }));
    it("should properly animate custom animations for general animation events",
      inject(function($animator, $rootScope, $compile, $sniffer) {
      $animator.enabled(true);
      var element = $compile(html('<div></div>'))($rootScope);
      animator = $animator($rootScope, {
        ngAnimate : "'special'"
      });
      animator.animate('custom',element);
      if($sniffer.transitions) {
        expect(element.hasClass('special-custom')).toBe(true);
        window.setTimeout.expect(1).process();
        expect(element.hasClass('special-custom-active')).toBe(true);
      }
      else {
        expect(window.setTimeout.queue.length).toBe(0);
      }
    }));
    describe("Animations", function() {
      it("should properly detect and make use of CSS Animations",
          inject(function($animator, $rootScope, $compile, $sniffer) {
        var style = 'animation: some_animation 4s linear 0s 1 alternate;' +
                    vendorPrefix + 'animation: some_animation 4s linear 0s 1 alternate;';
        element = $compile(html('<div style="' + style + '">1</div>'))($rootScope);
        var animator = $animator($rootScope, {
          ngAnimate : '{show: \'inline-show\'}'
        });
        element.css('display','none');
        expect(element.css('display')).toBe('none');
        animator.show(element);
        if ($sniffer.animations) {
          window.setTimeout.expect(1).process();
          window.setTimeout.expect(4000).process();
        }
        else {
          expect(window.setTimeout.queue.length).toBe(0);
        }
        expect(element[0].style.display).toBe('');
      }));
      it("should properly detect and make use of CSS Animations with multiple iterations",
          inject(function($animator, $rootScope, $compile, $sniffer) {
        var style = 'animation-duration: 2s;' + 
                    'animation-iteration-count: 3;' +
                    vendorPrefix + 'animation-duration: 2s;' + 
                    vendorPrefix + 'animation-iteration-count: 3;';
        element = $compile(html('<div style="' + style + '">1</div>'))($rootScope);
        var animator = $animator($rootScope, {
          ngAnimate : '{show: \'inline-show\'}'
        });
        element.css('display','none');
        expect(element.css('display')).toBe('none');
        animator.show(element);
        if ($sniffer.animations) {
          window.setTimeout.expect(1).process();
          window.setTimeout.expect(6000).process();
        }
        else {
          expect(window.setTimeout.queue.length).toBe(0);
        }
        expect(element[0].style.display).toBe('');
      }));
      it("should fallback to the animation duration if an infinite iteration is provided",
          inject(function($animator, $rootScope, $compile, $sniffer) {
        var style = 'animation-duration: 2s;' + 
                    'animation-iteration-count: infinite;' +
                    vendorPrefix + 'animation-duration: 2s;' + 
                    vendorPrefix + 'animation-iteration-count: infinite;';
        element = $compile(html('<div style="' + style + '">1</div>'))($rootScope);
        var animator = $animator($rootScope, {
          ngAnimate : '{show: \'inline-show\'}'
        });
        element.css('display','none');
        expect(element.css('display')).toBe('none');
        animator.show(element);
        if ($sniffer.animations) {
          window.setTimeout.expect(1).process();
          window.setTimeout.expect(2000).process();
        }
        else {
          expect(window.setTimeout.queue.length).toBe(0);
        }
        expect(element[0].style.display).toBe('');
      }));
      it("should consider the animation delay is provided",
          inject(function($animator, $rootScope, $compile, $sniffer) {
        var style = 'animation-duration: 2s;' + 
                    'animation-delay: 10s;' +
                    'animation-iteration-count: 5;' +
                    vendorPrefix + 'animation-duration: 2s;' + 
                    vendorPrefix + 'animation-delay: 10s;' +
                    vendorPrefix + 'animation-iteration-count: 5;';
        element = $compile(html('<div style="' + style + '">1</div>'))($rootScope);
        var animator = $animator($rootScope, {
          ngAnimate : '{show: \'inline-show\'}'
        });
        element.css('display','none');
        expect(element.css('display')).toBe('none');
        animator.show(element);
        if ($sniffer.transitions) {
          window.setTimeout.expect(1).process();
          window.setTimeout.expect(20000).process();
        }
        else {
          expect(window.setTimeout.queue.length).toBe(0);
        }
        expect(element[0].style.display).toBe('');
      }));
      it("should skip animations if disabled and run when enabled",
          inject(function($animator, $rootScope, $compile, $sniffer) {
        $animator.enabled(false);
        var style = 'animation: some_animation 2s linear 0s 1 alternate;' +
                    vendorPrefix + 'animation: some_animation 2s linear 0s 1 alternate;'
        element = $compile(html('<div style="' + style + '">1</div>'))($rootScope);
        var animator = $animator($rootScope, {
          ngAnimate : '{show: \'inline-show\'}'
        });
        element.css('display','none');
        expect(element.css('display')).toBe('none');
        animator.show(element);
        expect(element[0].style.display).toBe('');
      }));
      it("should finish the previous animation when a new animation is started",
        inject(function($animator, $rootScope, $compile, $sniffer) {
          var style = 'animation: some_animation 2s linear 0s 1 alternate;' +
                      vendorPrefix + 'animation: some_animation 2s linear 0s 1 alternate;'
          element = $compile(html('<div style="' + style + '">1</div>'))($rootScope);
          var animator = $animator($rootScope, {
            ngAnimate : '{show: \'show\', hide: \'hide\'}'
          });
          animator.show(element);
          if($sniffer.animations) {
            window.setTimeout.expect(1).process();
            expect(element.hasClass('show')).toBe(true);
            expect(element.hasClass('show-active')).toBe(true);
          }
          else { //animation is skipped
            expect(window.setTimeout.queue.length).toBe(0);
          }
          animator.hide(element);
          if(!$sniffer.animations) {
            expect(window.setTimeout.queue.length).toBe(0);
          }
          expect(element.hasClass('show')).toBe(false);
          expect(element.hasClass('show-active')).toBe(false);
      }));
    });
    describe("Transitions", function() {
      it("should skip transitions if disabled and run when enabled",
          inject(function($animator, $rootScope, $compile, $sniffer) {
        $animator.enabled(false);
        element = $compile(html('<div style="' + vendorPrefix + 'transition: 1s linear all">1</div>'))($rootScope);
        var animator = $animator($rootScope, {
          ngAnimate : '{show: \'inline-show\'}'
        });
        element.css('display','none');
        expect(element.css('display')).toBe('none');
        animator.show(element);
        expect(element[0].style.display).toBe('');
        $animator.enabled(true);
        element.css('display','none');
        expect(element.css('display')).toBe('none');
        animator.show(element);
        if ($sniffer.transitions) {
          window.setTimeout.expect(1).process();
          window.setTimeout.expect(1000).process();
        }
        else {
          expect(window.setTimeout.queue.length).toBe(0);
        }
        expect(element[0].style.display).toBe('');
      }));
      it("should skip animations if disabled and run when enabled picking the longest specified duration",
        inject(function($animator, $rootScope, $compile, $sniffer) {
          $animator.enabled(true);
          element = $compile(html('<div style="' + vendorPrefix + 'transition-duration: 1s, 2000ms, 1s; ' + vendorPrefix + 'transition-property: height, left, opacity">foo</div>'))($rootScope);
          var animator = $animator($rootScope, {
            ngAnimate : '{show: \'inline-show\'}'
          });
          element.css('display','none');
          animator.show(element);
          if ($sniffer.transitions) {
            window.setTimeout.expect(1).process();
            window.setTimeout.expect(2000).process();
          }
          else {
            expect(window.setTimeout.queue.length).toBe(0);
          }
          expect(element[0].style.display).toBe('');
        }));
      it("should skip animations if disabled and run when enabled picking the longest specified duration/delay combination",
        inject(function($animator, $rootScope, $compile, $sniffer) {
          $animator.enabled(false);
          element = $compile(html('<div style="' + vendorPrefix + 
            'transition-duration: 1s, 0s, 1s; ' + vendorPrefix +
            'transition-delay: 2s, 1000ms, 2s; ' + vendorPrefix + 
            'transition-property: height, left, opacity">foo</div>'))($rootScope);
          var animator = $animator($rootScope, {
            ngAnimate : '{show: \'inline-show\'}'
          });
          element.css('display','none');
          expect(element.css('display')).toBe('none');
          animator.show(element);
          expect(element[0].style.display).toBe('');
          $animator.enabled(true);
          element.css('display','none');
          expect(element.css('display')).toBe('none');
          animator.show(element);
          if ($sniffer.transitions) {
            window.setTimeout.expect(1).process();
            window.setTimeout.expect(3000).process();
          }
          else {
            expect(window.setTimeout.queue.length).toBe(0);
          }
          expect(element[0].style.display).toBe('');
      }));
      it("should select the highest duration and delay",
        inject(function($animator, $rootScope, $compile, $sniffer) {
          var styles = 'transition:1s linear all 2s;' + 
                       vendorPrefix + 'transition:1s linear all 2s;' + 
                       'animation:my_ani 10s 1s;' + 
                       vendorPrefix + 'animation:my_ani 10s 1s;';
          element = $compile(html('<div style="' + styles + '">foo</div>'))($rootScope);
          var animator = $animator($rootScope, {
            ngAnimate : '{show: \'inline-show\'}'
          });
          element.css('display','none');
          expect(element.css('display')).toBe('none');
          animator.show(element);
          if ($sniffer.transitions) {
            window.setTimeout.expect(1).process();
            window.setTimeout.expect(11000).process();
          }
          else {
            expect(window.setTimeout.queue.length).toBe(0);
          }
          expect(element[0].style.display).toBe('');
      }));
      it("should finish the previous transition when a new animation is started",
        inject(function($animator, $rootScope, $compile, $sniffer) {
          var style = 'transition: 1s linear all;' +
                      vendorPrefix + 'transition: 1s linear all;'
          element = $compile(html('<div style="' + style + '">1</div>'))($rootScope);
          var animator = $animator($rootScope, {
            ngAnimate : '{show: \'show\', hide: \'hide\'}'
          });
          animator.show(element);
          if($sniffer.transitions) {
            window.setTimeout.expect(1).process();
            expect(element.hasClass('show')).toBe(true);
            expect(element.hasClass('show-active')).toBe(true);
          }
          else { //animation is skipped
            expect(window.setTimeout.queue.length).toBe(0);
          }
          animator.hide(element);
          if(!$sniffer.transitions) {
            expect(window.setTimeout.queue.length).toBe(0);
          }
          expect(element.hasClass('show')).toBe(false);
          expect(element.hasClass('show-active')).toBe(false);
      }));
    });
  });
  describe('anmation evaluation', function () {
    it('should re-evaluate the animation expression on each animation', inject(function($animator, $rootScope) {
      var parent = jqLite('<div><span></span></div>');
      var element = parent.find('span');
      $rootScope.animationFn = function () { throw new Error('too early'); };
      var animate = $animator($rootScope, { ngAnimate: 'animationFn()' });
      var log = '';
      $rootScope.animationFn = function () { log = 'abc' };
      animate.enter(element, parent);
      expect(log).toEqual('abc');
      $rootScope.animationFn = function () { log = 'xyz' };
      animate.enter(element, parent);
      expect(log).toEqual('xyz');
    }));
  });
  it("should throw an error when an invalid ng-animate syntax is provided", inject(function($animator, $rootScope) {
    expect(function() {
      var animate = $animator($rootScope, { ngAnimate: ':' });
      animate.enter();
    }).toThrow("[$parse:syntax] Syntax Error: Token ':' not a primary expression at column 1 of the expression [:] starting at [:].");
  }));
});
 |