I am getting undefined as response for a mocked api call using jest.spyOn() and mockImplmentation.
Saga.tsx
export function* parseUserData(parsingAction: IParsingAction) {
try {
const skills = yield call(SkillRepository.getAllSkills);
console.log('------skils-----', skills); // undefined
const industries = yield call(IndustryRepository.getAllIndustry);
if (skills.skillGroup && industry.industryGroup)
{
yield put(getSkillsSuccess(skills.skillGroups));
yield put(getIndustriesSuccess(industry.industryGroups));
}
else
{
yield put(bulkUploadError());
}
} catch (error) {
yield put(bulkUploadError());
}
}
Saga.test.tsx
describe('ParseUserData job saga', () => {
const action = {
type: bulkUploadActionType.GET_API_DATA,
payload: {
sheetData: {},
isAdvisor: true,
},
};
const generator = parseUserData(action);
it('Should call skill repository', () => {
const skills = { skillGroups: [] };
const spy = jest.spyOn(SkillRepository, 'getAllSkills');
spy.mockImplementation((): any => {
return (skills);
});
expect(generator.next().value).toEqual(call(SkillRepository.getAllSkills));
spy.mockRestore();
});
});
Any help would be appreciated. Its very simple thing but I am stuck with this.