测试动画角度1.2+



有人知道如何在angular中测试动画吗?使用$animateProvider或angular.module('',[]).animate()生成的动画?我正在构建一个动画库,这很好,但我找不到使用$animate测试动画的正确方法。他们从不工作。我已经破解了它以开始工作,但我几乎在每个测试中重新创建所有的动画。为了确保这不是我的动画,我在测试中创建了一个新的。我直接从Angular的源代码中得到了这个,但它仍然不起作用。

describe('Testing Async Animations', function() {
  var am = false;
  beforeEach(module('ngAnimate'));
  beforeEach(module('ngAnimateMock'));
  beforeEach(module(function($animateProvider){
    $animateProvider.register('.fade', function(){
      return {
        enter: function(element, done){
          console.log('here');
          am = true;
          done();
        }
      };
    });
  }));
  /* the done() method is something mocha provides.
     to make this work in Jasmine, just follow their
     example with using a asynchronous test */
  it("should asynchronously test the animation", function() {
    inject(function($animate, $compile, $document, $rootScope, $rootElement) {
      var element = $compile('<div class="fade">hello</div>')($rootScope);
      $rootElement.append(element);
      angular.element($document[0].body).append($rootElement);
      $animate.enabled(true);
      $animate.enter(element, $rootElement);
      $rootScope.$digest();
      expect(am).to.be(true);
    });
  });
});

我测试动画的方式是正确的,但当时Angular在v1.2.16中对ngMocks进行了更改,这一切都搞砸了。

最新更新