I am currently attempting to unit test an API within my ngOnInit method. The method is responsible for making a call to the service in order to fetch details. If the details are not undefined, an array called 'shoeDataResponse' of type *shoeData [] will be populated with these details and returned as the response.
*shoeDataResponse: shoeData[];
Below is the implementation of the method:
ngOnInit(): void {
this.shoeService.getShoeData().subscribe((shoeDetails) => {
if (shoeDetails != undefined) {
this.shoeDataResponse = shoeDetails;
}
});
}
I am uncertain if this is the correct approach, but here is what I have attempted in the spec file:
it('should return data if defined', waitForAsync(() => {
let shoeDataResponse = [
{
mCompanyIDEntity: {
mbranchID: '108020',
misShippingItem: true,
mIsBranchNumber: false,
},
companyName: 'SOME COMPANY',
shoeBalance: 1250.00,
orderDate: '',
mAccountHolder: false,
},
];
spyOn(ShoeService, 'getShoeData').and.returnValue(of(shoeDataResponse));
component.ngOnInit();
expect(component).toBeTruthy();
}));
Upon running the test, I encounter an error stating, "Argument of type '"getShoeData"' is not assignable to parameter of type '"prototype"'."
Any assistance on resolving this issue would be highly appreciated. Thank you!!!