在业力中单元测试自定义$ animate动画

时间:2014-01-05 01:54:29

标签: angularjs animation karma-runner

我试图运行测试自定义addClass动画的单元测试。无论我尝试什么,包括在网上运行样本,都可以在业力测试运行中运行自定义动画。注意我的动画代码在工作站点中工作正常。我只是希望能够为我的动画生成茉莉花测试。

module.exports = function(config) {
  config.set({
  basePath: '',
  frameworks: ['jasmine'],
  files: [
      'Scripts\\angular.js',
      'Scripts\\angular-animate.js',
      'Scripts\\angular-mocks.js',
      'Scripts\\animate-scr.js',
      'Scripts\\animate-test.js',
  ],
  exclude: [
  ],
  reporters: ['progress'],
  port: 9875,
  colors: true,
  logLevel: config.LOG_INFO,
  autoWatch: true,
  browsers: ['Chrome'],
  captureTimeout: 60000,
  singleRun: false 
});
};

这是我动画的源代码。

var counter = 0;
var testapp = angular.module('testapp', ['ngAnimate']);

    testapp.counter = 2;

    testapp.animation('.footeropen', function() {
    return {
            addClass : function(element, className) {
            testapp.counter = 3;
        }
    };
});

这是我的单元测试代码

describe('Testing Animations', function() {
    beforeEach(module('testapp'));
    beforeEach(module('mock.animate'));

    it("should synchronously test the animation",
            inject(function($animate, $rootScope) {
        var element = angular.element('<div>hello</div>');
        $animate.addClass(element, 'footeropen');
        $rootScope.$digest();
        expect(testapp.counter).toBe(3);
    }));
});

1 个答案:

答案 0 :(得分:0)

令我失望的是,我发现模拟的动画对象主动停止addClass()和removeClass()上的自定义动画。代码中的确切注释是:

//There is no point in perform a class-based animation if the element already contains
//(on addClass) or doesn't contain (on removeClass) the className being animated.
//The reason why this is being called after the previous animations are cancelled
//is so that the CSS classes present on the element can be properly examined.

我已经看过没有模拟动画对象的运行它,这会导致类似的响应。

因此,此时无法进行测试。