如何编写订阅回调单元-Jasmine/Angular



我正在尝试编写一个类的单元测试,现在我想给">tableTrans";但我无法模拟这部分.subscribe(数据=>

需要帮助吗?

ngOnInit() { 
this.subscription.add(combineLatest([$stats, this.init()]).subscribe(data => {
// 1. assign data
this.tableTrans = this.translation.team.burnupAnalysis.table;
const tableTitle = this.translation.titles.export.bunUpAnalysisTableTitle;

}));
}

我试着嘲笑它,但没有成功

beforeEach(() => {
fixture = TestBed.createComponent(BurnupDetailsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
const spy = spyOn(component.subscription, 'add').and.callFake((data) => {
return ''
})

我发现我必须在我的商店的初始状态中为this.init((this.translation填充模拟数据。

最新更新