[英]Cannot Get Karma To Run My Angular2 Tests
I feel like I have tried everything.我觉得我已经尝试了一切。 The files are found, even the simplest tests won't run.
找到了文件,即使是最简单的测试也无法运行。 I show this:
我展示这个:
Chrome 49.0.2623 (Windows 7 0.0.0): Executed 0 of 0 SUCCESS (0 secs / 0 secs) Chrome 49.0.2623 (Windows 7 0.0.0): Executed 0 of 0 ERROR (0.003 secs / 0 secs)
I feel like I've tried everything.我觉得我什么都试过了。 I've tried different frameworks, Mocha/Chai - Jasmine, nothing.
我尝试过不同的框架,Mocha/Chai - Jasmine,什么都没有。 The debug tab doesn't show anything in chrome when I click it.
当我单击它时,调试选项卡在 chrome 中没有显示任何内容。
Project Dir: http://pastebin.com/1wQubhCt项目目录: http : //pastebin.com/1wQubhCt
karma.shim.js: http://pastebin.com/PtPnL82G karma.shim.js: http ://pastebin.com/PtPnL82G
karma.conf.js: http://pastebin.com/CU0aqnj6 karma.conf.js: http ://pastebin.com/CU0aqnj6
Example test (obviously expect to fail):示例测试(显然预计会失败):
import {
it,
expect,
describe,
beforeEachProviders
} from 'angular2/testing';
describe('myComponent', () => {
beforeEachProviders([]);
describe('creation', () => {
it('should do this', ()=> {
expect(1).toEqual(2)
})
});
});
At this point I recommend using Angular CLI when setting up an angular 2.0 project from scratch.在这一点上,我建议在从头开始设置 angular 2.0 项目时使用 Angular CLI。 It gives you a functional unit test runner and auto reloading for the website whenever you make a code change.
它为您提供功能单元测试运行程序,并在您更改代码时自动重新加载网站。
It removes all the tedious configuration steps you have to go through to set up the project.它消除了设置项目所需的所有繁琐配置步骤。
Check it out here: https://github.com/angular/angular-cli在这里查看: https : //github.com/angular/angular-cli
Running tests within Karma can be a bit painful because of the karma.shim.js
file.由于
karma.shim.js
文件,在 Karma 中运行测试可能会有点痛苦。 Most of time the problem is in this file.大多数时候问题出在这个文件中。
I think that there is a problem in this file and more particularly in the onlySpecFiles
function.我认为这个文件有问题,尤其是在
onlySpecFiles
函数中。 This should be /_test\\.js$/
instead of /_test\\.ts$/
:这应该是
/_test\\.js$/
而不是/_test\\.ts$/
:
function onlySpecFiles(path) {
return /_test\.ts$/.test(path);
}
You could see this question for more details:您可以查看此问题以获取更多详细信息:
对我来说,这个问题是通过更新 Angular-CLI 解决的:
npm install --save-dev @angular/cli@latest
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.