我正在设置我的Karma配置文件,但是我没有完全理解一些存在的选项,因为我没有成功地测试通过ngHtml2JsPreprocessor运行并且已经运行的模板设置ng-htmljs-preprocessor karma预处理器
$templateCached
在ngHtml2JsPreprocessor的内部,我可以添加几个涉及路径的键值属性。
ngHtml2JsPreprocessor: {
stripPrefix: ".*/Went all the way back to the root of my application/",
// moduleName: 'templatesCached'//
},
我注释掉了现在的模板,以确保我可以访问每个文件作为模块。我正在加载没有错误的模块。我可以在我的开发工具中找到templateCached版本。
beforeEach(module('template'));
我的模板文件夹位于我创建的基本路径之外。
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文件,但这似乎没有做任何事情
您是否在'files:[]'中包含了html文件?另外,尝试编译另一个'beforeEach'块中的元素。 – Jagrut
我做到了。我终于解决了这个问题,结果很简单 – Winnemucca