我在用cg-角钢作为我的项目的支架。
我正在测试一个使用templateUr和ng-html2js将模板加载到模块中的指令。当我使用Chrome作为浏览器运行我的测试时,它没有问题,但是当我使用Phantom运行它时,我得到:
Error: [$injector:modulerr] Failed to instantiate module templates due to:下面是我的Gruntfile的相关部分:
karma: {
options: {
frameworks: ['jasmine'],
preprocessors: {'directive/**/*.html':['ng-html2js']},
files: [ //this files data is also updated in the watch handler, if updated change there too
'<%= dom_munger.data.appjs %>',
'bower_components/angular-mocks/angular-mocks.js',
'directive/**/*.html',
createFolderGlobs(['*-spec.js'])
],
ngHtml2JsPreprocessor:{
moduleName:'templates'
},
logLevel: 'ERROR',
reporters: ['mocha'],
autoWatch: false, //watching is handled by grunt-contrib-watch
},
all_tests: {
browsers: ['PhantomJS', 'Chrome'],
singleRun:false
},
during_watch:{
browsers: ['PhantomJS'],
singleRun:true
}
}因此,运行运行karma:all_tests的咕噜测试,工作起来就像一个冠军。运行karma:during_watch的咕噜发球失败。
是否有一种方法来检查html2js是否实际正在运行?
编辑这不是幻影。如果我在“during_watch”任务中运行Chrome,它也会失败。
发布于 2014-11-03 15:18:51
弄明白了。我用发电机-cg-角钢支架这个项目。它使用咕噜表事件来设置一些选项。此事件仅在服务任务中使用,而不是在测试或生成期间使用。我没有注意到它正在覆盖karma.options,因此html2js从未被调用过。当我将其附加到Gruntfile的事件部分时,html2js将按应有的方式运行。下面是显示更改的Gruntfile的相关部分。
if (grunt.file.exists(spec)) {
var files = [].concat(grunt.config('dom_munger.data.appjs'));
files.push('bower_components/angular-mocks/angular-mocks.js');
files.push(spec);
files.push('directive/**/*.html'); // This one
grunt.config('karma.options.files', files);
grunt.config('karma.options.ngHtml2JsPreprocessor.moduleName', 'templates'); // And this one
tasksToRun.push('karma:during_watch');
}https://stackoverflow.com/questions/26682740
复制相似问题