Repository: angular/angular.js
File: test/ngAnimate/animateCssSpec.js (JavaScript)

Code before:
            var animator = $animateCss(element, { addClass: klass }).start();
            animator.done(onDone);
            triggerAnimationStartFrame();
            return animator;
          }
        }));

        it("should not throw an error any pending timeout requests resolve after the element has already been removed",
          inject(function($animateCss, $document, $rootElement, $timeout, $animate) {

          var element = jqLite('<div></div>');
          $rootElement.append(element);
          jqLite($document[0].body).append($rootElement);

          ss.addRule('.red', 'transition:1s linear all;');

          $animateCss(element, { addClass: 'red' }).start();
          triggerAnimationStartFrame();
          element.remove();

          expect(function() {
            $timeout.flush();
          }).not.toThrow();
        }));

        it("should consider a positive options.delay value for the closing timeout",
          inject(function($animateCss, $rootElement, $timeout, $document) {

          var element = jqLite('<div></div>');
          $rootElement.append(element);
          jqLite($document[0].body).append($rootElement);

          var options = {
            delay: 3,
            duration: 3,
            to: {
              height: '100px'
            }
          };

          var animator = $animateCss(element, options);

          animator.start();
          triggerAnimationStartFrame();

          expect(element.css(prefix + 'transition-delay')).toContain('3s');

          // At this point, the animation should still be running (closing timeout is 9000ms)
          $timeout.flush(5000);

          expect(element.css(prefix + 'transition-delay')).toContain('3s');

Review comment (bug):
I'm not sure why this test fails. It should ensure that the animation ends exactly then when it's supposed to be, not before. And it passed locally for me.


Code after:
            var animator = $animateCss(element, { addClass: klass }).start();
            animator.done(onDone);
            triggerAnimationStartFrame();
            return animator;
          }
        }));

        it("should not throw an error any pending timeout requests resolve after the element has already been removed",
          inject(function($animateCss, $document, $rootElement, $timeout, $animate) {

          var element = jqLite('<div></div>');
          $rootElement.append(element);
          jqLite($document[0].body).append($rootElement);

          ss.addRule('.red', 'transition:1s linear all;');

          $animateCss(element, { addClass: 'red' }).start();
          triggerAnimationStartFrame();
          element.remove();

          expect(function() {
            $timeout.flush();
          }).not.toThrow();
        }));

        it("should consider a positive options.delay value for the closing timeout",
          inject(function($animateCss, $rootElement, $timeout, $document) {

          var element = jqLite('<div></div>');
          $rootElement.append(element);
          jqLite($document[0].body).append($rootElement);

          var options = {
            delay: 3,
            duration: 3,
            to: {
              height: '100px'
            }
          };

          var animator = $animateCss(element, options);

          animator.start();
          triggerAnimationStartFrame();

          // At this point, the animation should still be running (closing timeout is 7500ms ... duration * 1.5 + delay => 7.5)
          $timeout.flush(7000);

          expect(element.css(prefix + 'transition-delay')).toBe('3s');
          expect(element.css(prefix + 'transition-duration')).toBe('3s');