I want to create a unit test for this calculation. I will use this sum function in my other component to calculate values coming from the API. Cats and dogs in that case will be the fetched data.
export const sum = (value, number, type) => {
let result;
switch (type) {
case 'cats':
result = round(sumBy(slice(value, 0, number), 'cats'));
return Number.isNaN(result) ? 0 : result;
case 'dogs':
result = round(sumBy(slice(value, 0, number), 'dogs'));
return Number.isNaN(result) ? 0 : result;
default:
return 0;
}
};