I recently started diving into Jest and am looking for alternative methods to test this function regarding the If case and return statement using Jest. Here is the function I need help testing:
const extractInfo = (description: string) => {
const info= description.match('descriptionInformation');
if (info) {
return info[0];
}
return 'hello jest';
};
I have attempted the following test cases in Info.test.ts:
test('extractInfo method should be defined', () => {
expect(extractInfo).toBeDefined();
});
test('extractInfo should be called with a blank string as input', () => {
const BLANK_STRING = '';
expect(extractInfo).toHaveBeenCalled();
expect(extractInfo).toHaveBeenCalledWith(BLANK_STRING);
})
const extractInfo = (Info: string) => {
const info= description.match(jestinformation);
if (info) {
return info[0];
}
return 'hello jest';
};
If you could provide some guidance on how to cover each line of the function, it would be greatly appreciated. Thank you.