如何为订户模拟数据

时间:2019-04-12 17:02:13

标签: angular unit-testing

我正在angular应用上运行单元测试,我想传递数据以进行订阅,如下面的代码所示,我尝试了多种方法让我知道哪个是正确的

getData() {

    this.http.post<Transactions[]>('/api/getrecords', this.filter)
    .subscribe(res => {
      if (res['status'] == "FAILURE") {

      //do something
      } else {
        console.log(res['status']);
        this.data = res['data'];
        }
}

试图像这样传递getData

 mockService.getData=of(mockUsageRecords);//tried this
 mockService.getData=mockUsageRecords;//tried this
 mockService.getData.and.returnValue(of(mockUsageRecords));//this one gives error

0 个答案:

没有答案