karma-ng-html2js-处理器未创建模块
karma-ng-html2js-preprocessor not creating modules
正在尝试使用karma-ng-html2js-preprocessor。Karma发现我所有的其他东西(javascript)都很好,但当涉及到这个html预处理器时,它似乎无法找到并从中生成模块
查看下面的选项对象。正如您所看到的,我已经向files属性添加了一个模式,并且我正在为模块使用通用名称"foo"。在测试中,每当我尝试调用module('foo');
时,因果报应都会抛出一个错误我真的希望能够使用它,这样我就不必将模板硬编码到我的单元测试或其他一些古怪的解决方案中。
var options = {
files: [].concat(
bowerFiles,
config.specHelpers,
clientApp + '**/*.module.js',
clientApp + '**/*.js',
clientApp + '**/*.html',
'*.html',
temp + config.templateCache.file,
config.serverIntegrationSpecs
),
exclude: [],
coverage: {
dir: report + 'coverage',
reporters: [
// reporters not supporting the `file` property
{ type: 'html', subdir: 'report-html' },
{ type: 'lcov', subdir: 'report-lcov' },
{ type: 'text-summary' } //, subdir: '.', file: 'text-summary.txt'}
]
},
ngHtml2JsPreprocessor: {
// strip this from the file path
// stripPrefix: clientApp,
moduleName: 'foo'
},
preprocessors: {}
};
options.preprocessors[clientApp + '**/*.html'] = ['ng-html2js'];
options.preprocessors[clientApp + '**/!(*.spec)+(.js)'] = ['coverage'];
return options;
}
我知道这不一定能回答你的问题,如果有更多信息曝光,我会添加到这个答案中,但我发现这个策略效果很好。。。
我发现指令、路由或状态的HTML模板(如果使用ui-router)在单元测试时不应该发挥作用。单元测试就是测试组件的接口;其公开可用的方法和属性。测试与HTML文档的交互实际上是使用Protractor之类的东西进行端到端测试的领域。
考虑到这一点,以下是我如何防止Karma在测试期间尝试加载模板文件。
beforeEach(function() {
module('module.name.of.the.testable.component');
inject(function($templateCache) {
$templateCache.put('path/to/template/as/it/appears/in/your/component.html',
'<div></div>');
});
});
相关文章:
- Javascript中的模块模式和揭示模块模式是否仅在创建API时有用;s
- 使用grunt模块创建svg精灵
- 要求创建空模块作为依赖项加载程序
- 使用ES6模块创建JS
- 如何在新创建的模块中从Odoo v8中的Javascript文件中调用python函数
- 如何使用默认函数导出为 commonjs 模块创建类型
- 创建javascript模块
- Node.js创建一个模块来收集内存(ram)信息
- 如何在redux模块中创建一个helper类型的函数,从state返回一组经过过滤的只读数据
- 是否可以创建一个require.js模块,该模块在加载完成后自行决定
- Backbone app:将参数传递给由javascript/Require模块创建的新类
- TypeScript:从模块创建全局变量
- 正在node.js中为所需模块创建回调
- System.NullReferenceException:对象引用未设置为对象的实例.Dotnetnuke模块创建
- 如何优化作为RequireJS模块创建的JavaScript文件子集
- Angular2 cli (Webpack)为不同的模块创建块
- 为require节点模块创建工厂
- 如何在纯js中使用AMD模块创建typescript类的对象实例
- Rangy:如何获取使用Highlighter模块创建的跨度元素
- 尝试使用导出.从Node.js中的另一个模块创建