我试图测试我的指令,但当我用karma加载所有内容时,我使用ng-html2js。
它可以正常加载模块,然后在
上失败Error: Unexpected request: GET modules/contenteditable/contenteditable.html?v=1
No more request expected
实际问题
那么如何将url参数添加到我的ng-html2js模块中呢?
因为我们使用?v = VERSIONNUMBER为每个模板文件添加缓存,所以即使指令也会模板化
Karma配置
preprocessors: {
'common/modules/**/*.html': 'ng-html2js'
},
ngHtml2JsPreprocessor: {
stripPrefix: 'common/',
moduleName: function (htmlPath, originalPath) {
return htmlPath;
}
},
测试
describe("contenteditable", function() {
var elm, $compile, $rootScope;
beforeEach(function(){
module(
'angularModalService',
'constant.phpConstants',
'directive.contenteditable',
'modules/contenteditable/contenteditable.html'
);
angular.mock.module('ngMockE2E');
inject(function(_$compile_, _$rootScope_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
});
elm = angular.element('<rte></rte>');
scope = $rootScope;
$compile(elm)(scope);
scope.$digest();
});
it("should compile the widget", function() {
console.log(elm[0]);
});
});