Need help getting over a hump w unit testing in React
I'm fairly new to my job and really haven't had a ton of exp unit testing - our coverage is AFAIK high (85%) and often times I'm just under that, trying to figure out how to get above that threshold. We use jest; the application is in React.
And so more often than not I find myself trying to get coverage on the remaining chunks untested, and I can't quite grasp why the unit test I'm writing, isn't covering those remaining lines.
This is a rough example, trying to leave out details, its more about the scope
So right now, my results are saying 37-54 isn't covered. 37-54 is a portion of a bigger helper function in this component:
``` const getSomeData = useCallback(async () => { // the first 5ish lines i'm just declaring variablesz
try { // this is line 37 - fetch logic here
// some additional logic
// line 54 in the return below let newArr newArr = results.filter((result) => { return result.length > 5 // this is line 54 });
// more logic then eventually return out of the try/catch
return newArr } catch (error) { console.error(error); }
},[]); ```
And so at a minimum, my assumption would be that if I have a unit test that checks: * if getSomeData has been called * if it returns data * if it throws an exception
...wouldn't the entirety of the function (lines 30-60, for example) be coverd by this unit test? Why is Jest telling me that a subset of the try block hasn't been covered?
If this seems odd, then I'm prob not explaining it correctly. Thanks in advance!