xyzcompone.ts
import {Invoice, InvoiceResponse, SupplierService} from "xyz";
@Component({
selector: 'invoice-container',
templateUrl: './container.component.html',
styleUrls: ['./invoice-container.component.scss']
})
export class xyzomponent implements OnInit {
constructor(
private supplierService: SupplierService,
public store: InvoicesStore) {}
onpaginaterequestsTable = async (payload: InvoicesRqModel) => {
const returnModel = payload;
this.supplierProducerService.retrieveinvoice(
returnModel.getModel.filterByParty
).subscribe(async (res: InvoiceResponse) => {
returnModel.updateTableData(
cleanTableData(res.invoices, (row: any) => {
return this.cleanDataRows(row);
})
);
await this.store.setRequestListModel(returnModel);
},
error => {
console.log('Unable to retrieve data');
}
);
};
cleanDataRows(row: Invoice) {
const cleanObj = {
...row
};
return cleanObj;
}
我想为onpaginaterequestsTable编写测试,但无法成功, 我曾尝试嘲笑针对retrieveinvoice的服务调用,但无法完全测试该问题,因为我在下一次聊天时共享我的测试代码(当前正在调试)
这是spec.ts文件
it('Test', async() => {
let dummyPayload: InvoicesRqListModel = new InvoicesRequestsListModel();
component.onpaginaterequestsTable(dummyPayload);
jest.spyOn(component.store,"setRequestListModel")
jest.spyOn(component,"cleanExchangeRequestDataRows")
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(component.store.setRequestListModel).toBeCalled(); //not matching
expect(component.cleanExchangeRequestDataRows).toBeCalled(); //not matching
expect(component.paginateRequestListLoading).toEqual(false); //true
});
});