【发布时间】:2017-07-21 14:36:43
【问题描述】:
文件结构(Angular 2官网的快速入门项目):
一开始,在启动 Karma 时,我收到错误说在 /@angular/ 下找不到两个文件...
我发现我必须更改 systemjs.config.js 中的路径才能使其正常工作:
/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': '/base/node_modules/' <<<<<<<------ Vincent: to be able to run the test,
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
'app': 'app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
defaultExtension: 'js',
meta: {
'./*.js': {
loader: 'systemjs-angular-loader.js'
}
}
},
rxjs: {
defaultExtension: 'js'
}
}
});
})(this);
所以,至少 Karma 现在可以工作了,我可以运行其他测试。但是,组件测试失败,因为它找不到组件的外部模板和样式文件。
我曾经可以通过在我的 Chrome 中打开:http://localhost:9876/base/src/app/app.component.html 来打开 html,但现在找不到了。
尝试了这个答案:https://stackoverflow.com/a/39909929/3634727,所有解决方案都在这里:Error: Uncaught (in promise): Failed to load login.component.html,没有运气。
我的第 1 个问题是,让我们把设置放在一边,在我的浏览器中打开 app.component.html 的正确 URL 是什么? http://localhost:9876/src/app/app.component.html 不起作用。
【问题讨论】:
标签: javascript angular unit-testing