angular - 角度 6 单元测试
问题描述
我正在开展一个项目,在该项目中,我从多个 3rd 方 api 获取报告数据,并将其显示在带有自定义过滤器和其他内容的表中。它工作正常,但我在测试时遇到问题。我有 1 个 json 文件,其中包含每个面板的凭据和端点。应用程序启动后,我立即读取该文件。
// factory that reads file
export function akrpFactory(akrp: AkrpService) {
return () => akrp.load();
}
// akrp.load method returns this.http.get("./assets/data.json")
// inside ngModule
providers: [
{
provide: APP_INITIALIZER,
useFactory: akrpFactory,
deps: [AkrpService],
multi: true
}
]
// after this data is available throughout the application
在仪表板组件 ngAfterViewInit 中有一个 http 调用
ngAfterViewInit() {
this.getPerformingFeeds(this.selectedPanel.key, '0-100');
}
// this.selectedPanel.key contains one of data records from json file
// here I am getting error ('TypeError: Cannot read property 'key' of undefined') during testing
在 .spec.ts 文件中只有一个测试用例。我试图分配 component.selectedPanel 但仍然是同样的错误
it('should create', () => {
expect(component).toBeTruthy();
});
好吧,我是 Angular 2+ 版本的新手,并且还在测试,不知道该怎么做。任何事情都会有帮助,谢谢。
解决方案
推荐阅读
- wpf - 将wpf App带到后台运行的前台?
- amazon-web-services - 在 AWS Glacier 中上传单个文件时出现大量请求
- javascript - 在 React Native 中使用 React-Native-Router-Flux 将标签栏添加到具有自己的导航堆栈的子场景
- java - 致命例外:使用 Firebase 的令牌刷新器
- c# - C# Winform - 当我将面板背景颜色放在其他人的右下角时,我的面板背景颜色一直消失
- android - 如何清理 AOSP 中的模块?
- .net - Dapper 和 SQL 注入
- java - Java 优先级 - 强制转换和位运算符
- excel - IF else 语句在 vba 代码中无法正常工作
- c# - ASPXRichedit 无法将 byte[] 隐式转换为 System.IO.Stream