我正在尝试为angular2中的组件编写单元测试。堆栈是angular2,karma,jasmine,Visual Studio作为IDE。在下面找到通过Gulp运行单元测试时发生的异常。
**16 03 2017 18:04:28.169:DEBUG [middleware:source-files]: Fetching E:/TestProject/app/component/SampleComponent
16 03 2017 18:04:28.170:WARN [web-server]: 404: /base/app/component/SampleComponent
Chrome 56.0.2924 (Windows 7 0.0.0) ERROR
{
"originalStack": "Error: Error: XHR error (404 Not Found) loading app/component/SampleComponent\n\tError loading app/component/SampleComponent as \"./SampleComponent\" from app/component/SampleComponent.spec.js",
"zoneAwareStack": "Error: Error: XHR error (404 Not Found) loading app/component/SampleComponent\n\tError loading app/component/SampleComponent as \"./SampleComponent\" from app/component/SampleComponent.spec.js",
"originalErr": {
"originalStack": "Error: XHR error (404 Not Found) loading app/component/SampleComponent",
"zoneAwareStack": "Error: XHR error (404 Not Found) loading app/component/SampleComponent"
}
}
Chrome 56.0.2924 (Windows 7 0.0.0) ERROR
{
"originalStack": "Error: Error: XHR error (404 Not Found) loading app/component/SampleComponent\n\tError loading app/component/SampleComponent as \"./SampleComponent\" from app/component/SampleComponent.spec.js",
"zoneAwareStack": "Error: Error: XHR error (404 Not Found) loading app/component/SampleComponent\n\tError loading app/component/SampleComponent as \"./SampleComponent\" from app/component/SampleComponent.spec.js",
"originalErr": {
"originalStack": "Error: XHR error (404 Not Found) loading app/component/SampleComponent",
"zoneAwareStack": "Error: XHR error (404 Not Found) loading app/component/SampleComponent"
}
}
16 03 2017 18:04:28.258:DEBUG [karma]: Run complete, exiting.
16 03 2017 18:04:28.259:DEBUG [launcher]: Disconnecting all browsers**
我的文件夹结构是app \ component
测试在组件文件夹本身中可用。已编译的js中的相关代码如下
const Component_1 = require("./SampleComponent");
const testing_1 = require("@angular/core/testing");
请求任何人提供帮助。
谢谢
TTV
答案 0 :(得分:0)
我通过 karma.conf.js
中的以下声明解决了这个问题{ pattern: './app/component/LoginComponent.js', included: true, watched: false }
请参阅以下网址以获取完整信息。
https://psamsotha.github.io/angular/2016/12/16/angular2-testing-karma-systemjs.html
检查