and.callthrough返回空数组

时间:2019-04-23 18:30:48

标签: angular typescript unit-testing

我正在角度应用程序上运行单元测试,我看到登录到屏幕时通过单元测试初始化​​的变量会打印出空数组。

console.log(component.records);//prints empty array[ ]
console.log(mockReturns['data']['Records']);//prints entire array

单元测试


//Intialization
let mockReturns={
    data:

    {
      Customer:{
        "CustomerName": "Stress_Test",
      },
      Products:[],
      Records:
      [
        {
          "ActivationId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
       "ActivationState": "Deployed",
          "Address": "",
      "AllowPortalLogin": "Yes",
     },
         ....
       ]
     }//close data
}//overall object

    component.records=mockReturns['data']['Records'];
    component.headers=mockheaders;
    fixture.detectChanges();
    let spyOnProductsTable=spyOn(component,'getData').and.callThrough();
    component.getData();
    fixture.detectChanges();




component.ts

 this.records = res['data']['Records'] as Array<any>;

0 个答案:

没有答案