angular - Angular Jasmin 如何为以下基于组件订阅的组件代码编写单元测试代码
问题描述
我正在 Angular 中处理测试用例,但无法在以下代码库上取得进展。
构造函数(私有路由器:路由器,私有 cd:ChangeDetectorRef,私有 dbs:DashboardService,){ const navigation = this.router.getCurrentNavigation(); if (navigation) { const state = navigation.extras.state as any; if (state) { this.memberView = state; if (state.Ids.length) { this.Ids.setValue('Ids', state.userIds); } this.dbs.emitViewUpdated({ ind: 1, Ids: state.userIds }); } } }
ngOnInit() {
this.loadCards = false;
this.Ids= [];
this.subscription = this.dbs.membersUpdated$.subscribe((ids: any) => {
this.cd.detectChanges();
this.Ids= ids;
this.loadCards = true;
});
this.Ids= this.dbs.getValue('Ids');
this.loadCards = this.Ids?.length ? true : false;
}
Spec.ts File
it('ngoninit', fakeAsync(() => {
const ids = [1, 2]
dbs.membersUpdated$ = of(true);
component.ngOnInit();
}));
I am very in new Angular test case. Thanks in Advance
解决方案
推荐阅读
- google-bigquery - 多次成功查询后,批处理作业偶尔会出现“没有 bigquery.jobs.create 权限”错误
- c# - SquidCoin.cs 我的货币脚本在添加 [PlayerPrefs] 后不起作用
- sql - PostgreSQL:意外的数组元素
- c# - ASP.Net Core 2.1 中的自定义授权过滤器与策略
- visual-studio - 将 SSRS 从 2016 年降级至 2008 年
- android - 具有上一页和下一页边界的 RecyclerView?
- php - 一个php页面中的MYSQL多选查询
- azure-active-directory - 带有 Azure AD 的身份服务器
- ios - 为 collectionView 中的每个其他项目设置特定布局
- arrays - Swift 将相同的数组值传递给 PHP/MySQL