尝试使用单独文件中的模板对 angular 的 1 指令进行单元测试。使用 jasmine 和 ng-html2js 将 html 模板存储在 $templateCache 中。在没有 SystemJS 的项目中,可以使用:
beforeEach(module('MyStupidModule', 'templates'))
其中模板 - 在“carma.conf.js”中
preprocessors: {
'Content/templates/**/*.html' : ['ng-html2js']
},
ngHtml2JsPreprocessor:{
moduleName: 'templates'
},
它工作得很好。
但是对于 SystemJS,我们现在必须实例化这两个模块以使它们可以访问。模拟我自己的模块很简单,
...
mockAngularModule('MyStupidModule');
// angular.mock.module('MyStupidModule');
angular.mock.module('store', 'templates');
..
但是我在哪里可以把这个“模板”模块的实例化?现在它抛出
错误:[$injector:modulerr] 无法实例化模块模板,原因是:错误:[$injector:nomod] 模块“模板”不可用!