【发布时间】:2014-10-29 18:32:14
【问题描述】:
我正在尝试使用 karma 预处理器,以便在单元测试中加载模板。
我的 angularjs 指令单元测试在运行测试时抛出“无法实例化模块错误”。我在 karma.conf.js 中使用 karma html2js 预处理器来获取指令单元测试中的模板。
karma.conf.js
config.set({
preprocessors: {
'Components/navBar/Templates/navBar.htm': ['ng-html2js']
},
files: [
'Scripts/angular-mocks.js',
...
...
'Client/Components/navBar/Templates/navBar.htm'
],
ngHtml2JsPreprocessor: {
moduleName: 'templates'
}
navBar_testcase.js
describe("navbartesting",
function () {
var template;
beforeEach(module('templates'));
beforeEach(function () {
module("navBar");
inject(function ($rootScope, $compile, $httpBackend, $injector, $localStorage, $state, $templateCache, userSession, appConfig) {
http = $httpBackend;
$httpBackend = $injector.get('$httpBackend');
...
....
});
});
});
在运行上述单元测试时,会抛出错误“无法实例化模块“模板””。这可能是什么问题?我们是否有任何物理路径要定义为在 karma 配置文件中包含“模板”模块?
【问题讨论】:
标签: javascript angularjs unit-testing karma-jasmine