测试角度1.2+的动画

时间:2014-04-22 03:03:47

标签: javascript angularjs testing

任何人都知道如何以角度测试动画?使用$ 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);

    });
  });

});

1 个答案:

答案 0 :(得分:0)

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

相关问题