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

how to write unit for subscribe callback - Jasmine / Angular

我正在尝试编写 class 的单元测试,现在我想将模拟值分配给“tableTrans”,但我无法模拟这部分 .订阅(数据=>

需要帮助吗?

 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 填充模拟数据在我商店的初始状态。