我正在设置我的 Karma 配置文件,但我不完全理解存在的一些选项,因为我没有成功测试已经通过 ngHtml2JsPreprocessor 并且已经
$templateCached
在 ngHtml2JsPreprocessor 内部,我可以添加一些涉及路径的键值属性。
ngHtml2JsPreprocessor: {
stripPrefix: ".*/Went all the way back to the root of my application/",
// moduleName: 'templatesCached'//
},
我现在注释掉了模板,以确保我可以作为模块访问每个文件。我正在加载没有错误的模块。我可以在我的开发工具中找到 templateCached 版本。
beforeEach(module('template'));
我的 Templates 文件夹位于我创建的基本路径之外。
basePath: 'Scripts/',
我在预处理器对象中引用了它
preprocessors: {
'../Templates/**/*.html' : ['ng-html2js']
},
同样,我的所有模板现在都是 js 文件并被缓存。
我在package.json 中将文件保存为
save-dev
"karma-chrome-launcher": "^0.2.2",
"karma-jasmine": "^0.2.2",
"karma-ng-html2js-preprocessor": "^0.2.1",
我在插件中引用了我的安装。
plugins: [
'karma-chrome-launcher',
'karma-jasmine',
'karma-sinon',
'karma-ng-html2js-preprocessor'
],
我已加载所有文件
files: [
//jquery libaries
// angular libraries
// Scripts files
// source app.js
// tests folder and files
]
我的测试从业力开始运行
但是,我的指令只是一个空字符串
element.html()
返回“”
我已经设置了吟游诗人注入
bard.inject(
"$compile",
"$controller",
"$rootScope",
'$templateCache',
"haConfig",
"$q"
);
这是我的 beforeEach 的内部
bard.mockService(haConfig, {
getTemplateUrl: '/tst!'
});
//bard.mockService(haConfig, {});
console.log('ha config2', haConfig.getTemplateUrl());
var html = angular.element("<div explore-hero></div>");
console.log('htl',haConfig.getTemplateUrl());
scope = $rootScope.$new();
//templateCache
element = $compile(html)(scope);
//console.log(haConfig.getTemplateUrl(html));
scope.$digest(element);
console.log('missing text',haConfig.getTemplateUrl(html));
controller = element.scope();
console.log("element", element);
我不知道为什么我得到一个空字符串。我正在创建 html 文件,但里面没有任何内容。
我只想知道是否应该将模板缓存文件显示在我的开发工具的文件夹中?还有是否应该在karma.conf.js的文件数组中引用文件
现在我引用了 html 文件?我已经尝试过 js 文件,但似乎没有做任何事情