我目前正在编写一个简单的测试来测试一个 Angular 2 组件,该组件的模板被 templateUrl 引用。我目前正在使用 webpack 来执行所需的任务,包括测试。我正在关注Angular 网站上的 webpack 指南 以及 AngularClass 的angular2-webpack-starter repo。
但是,当测试尝试创建组件夹具时,使用
testBed.createComponent(AppComponent);
我收到以下错误:
"'未处理的 Promise 拒绝:', '加载 app.component.html 失败', '; Zone:', 'ProxyZone', '; Task:', 'Promise.then', '; Value:', 'Failed to加载 app.component.html',"
因此显然导致测试失败。
在我的 app.component.ts 我通过 templateUrl 像这样引用模板
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
title = "Tour of Heroes";
}
我环顾四周,但没有找到解决此错误的方法。请问有人知道这个问题吗?到目前为止我遇到的所有示例(例如,此 repo https://github.com/rangle/angular2-redux-example中的示例)都包含内联 html。
如果你想查看 webpack / karma 配置文件,这里是我的 repo 的链接。 https://github.com/jeanpaulattard/tourofheroes
编辑:更新了我的仓库主分支的链接。