似乎没有得到karma-ng-html2js-preprocessor'做它的工作

时间:2014-09-24 13:55:55

标签: angularjs unit-testing karma-runner ng-html2js

继续给我这个错误:模块'模板'不可用!您要么错误拼写了模块名称,要么忘记加载它。

我在几个Angular项目中实现了Directives的单元测试,现在它似乎无法工作。这是我的karma.conf

module.exports = function(config){
config.set({

    basePath : '../',

    files : [
        'webapp/lib/bower_components/angular/angular.js',
        'webapp/lib/bower_components/angular-route/angular-route.js',
        'webapp/lib/bower_components/angular-resource/angular-resource.js',
        'webapp/lib/bower_components/angular-animate/angular-animate.js',
        'webapp/lib/bower_components/angular-mocks/angular-mocks.js',
        'webapp/lib/bower_components/jquery/jquery.js',
        'webapp/lib/jasmine-jquery.js',
        'webapp/js/components/**/*.html',
        'webapp/app.js',
        'webapp/js/**/*.js',
        'test/unit/**/*.js',
        { pattern: 'webapp/stubs/*', watched: true, served: true, included: false }
    ],

    preprocessors: {
        'webapp/js/components/**/*.html': ['ng-html2js']
        //'webapp/components/**/.js' : ['coverage']
    },

    autoWatch : true,

    frameworks: ['jasmine'],

    browsers : ['Chrome'],

    plugins : [
        'karma-chrome-launcher',
        'karma-firefox-launcher',
        'karma-jasmine',
        'karma-ng-html2js-preprocessor'
    ],

    junitReporter : {
        outputFile: 'test_out/unit.xml',
        suite: 'unit'
    },

    ngHtm2JsPreprocessor: {
        moduleName: 'templates'
    }
});
};

我绝对100%确定给定位置的.html文件。我仔细检查了说明,它只是不会在规范文件中加载beforeEach(module('templates'));

我在这里遗漏了什么吗?最有可能: - )

- 编辑:忘了' js'在路径' webapp / js / components / ** / * .html',仍然无法正常工作。

1 个答案:

答案 0 :(得分:0)

错误消息

Error: [$injector:modulerr] Failed to instantiate module templates due to:
Error: [$injector:nomod] Module 'templates' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

可通过在插件中安装和列出karma-html2js-preprocessor来重现

plugins : [
        'karma-chrome-launcher',
        'karma-firefox-launcher',
        'karma-jasmine',
        'karma-junit-reporter',
        'karma-html2js-preprocessor'
        ],

而不是karma-ng-html2js-preprocessor

plugins : [
        'karma-chrome-launcher',
        'karma-firefox-launcher',
        'karma-jasmine',
        'karma-junit-reporter',
        'karma-ng-html2js-preprocessor'
        ],