【发布时间】:2021-05-26 23:15:47
【问题描述】:
如何使用 jest 和 angular 对以下商店进行单元测试,sonarqude 不包括这条线。谢谢回复
在我的 component.ts 中
public ngOnInit(): void {
this.store
.select(studentfilesGetData)
.pipe(takeUntil(this.destroy$))
.subscribe(studentFiles => {
this.studentFiles = this.getSortedEmployerFiles(studentFiles );
});
}
在我的 component.spec.ts 中
beforeEach(() => {
store = mock(Store);
component = new myComponent(instance(store));
when(store.select(studentfilesGetData)).thenReturn(of(studentFiles));
});
describe('ngOnInit', () => {
test('should create', () => {
expect(component).toBeTruthy();
});
})
【问题讨论】: