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