似乎无法获得'karma-ng-html2js-preprocessor'的工作

San*_*con 5 unit-testing angularjs 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'
    }
});
};
Run Code Online (Sandbox Code Playgroud)

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

我在这里错过了什么吗?最可能 :-)

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

Nic*_*ray 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.
Run Code Online (Sandbox Code Playgroud)

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

plugins : [
        'karma-chrome-launcher',
        'karma-firefox-launcher',
        'karma-jasmine',
        'karma-junit-reporter',
        'karma-html2js-preprocessor'
        ],
Run Code Online (Sandbox Code Playgroud)

而不是 karma-ng-html2js-预处理器

plugins : [
        'karma-chrome-launcher',
        'karma-firefox-launcher',
        'karma-jasmine',
        'karma-junit-reporter',
        'karma-ng-html2js-preprocessor'
        ],
Run Code Online (Sandbox Code Playgroud)