Angular ng-FitText.js导致Karma测试失败

时间:2014-10-07 15:25:14

标签: angularjs plugins karma-runner

我已按照http://patrickmarabeas.github.io/ng-FitText.js/上非常简单的安装说明将FitText包含在我的项目中。

它现在在该项目中运作良好,但未能通过Karma测试给出此消息:

由于以下原因无法实例化模块myProject: Error: [$injector:modulerr]

如果有人有任何建议,他们会非常感激。 从应用程序中排除ngFitText使我们没有错误。

1 个答案:

答案 0 :(得分:0)

我认为我们可能需要更多信息。

猜测 - Angular根本无法找到要加载的模块。即使您没有使用该插件进行测试,Angular也希望所有模块依赖都存在。是否有可能将模块从Karma配置文件的files部分中删除,或者它的路径不正确(即因此Karma在运行测试时不包括它)? Karma不了解HTML中的<script>标记,因此您需要在运行代码时明确告诉它代码外部的任何依赖项。

例如,我的一个Karma配置文件具有以下内容(bower_components/...都是外部依赖项):

module.exports = function(config) {
    'use strict';
    config.set({
    ...
    files: [
        'bower_components/jquery/dist/jquery.js',
        'bower_components/angular/angular.js',
        'bower_components/angular-animate/angular-animate.js',
        'bower_components/angular-cookies/angular-cookies.js',
        'bower_components/angular-mocks/angular-mocks.js',
        'bower_components/angular-resource/angular-resource.js',
        'bower_components/angular-route/angular-route.js',
        'bower_components/angular-sanitize/angular-sanitize.js',
        'bower_components/angular-touch/angular-touch.js',
        'bower_components/matchmedia/matchMedia.js',
        'bower_components/matchmedia-ng/matchmedia-ng.js',
        'app/assets/scripts/**/*.js',
        'app/assets/tests/mock/**/*.js',
        'app/assets/tests/spec/**/*.js'
    ],
    ...
    });
};

如果上述方法没有帮助,那么我认为您需要粘贴Karma配置以及完整的错误消息和堆栈跟踪。

如果您需要更多详细信息,请与我们联系。