So my code is this:
const handler = (event = { body: {} }) => {
if (isEventEmpty(event)) {
return Promise.resolve({})
}
const getPayload = R.compose(
R.flatten,
R.map(x => transformRecord(x)),
R.pluck('Stuff'),
R.path(['body'])
)
const processEvent = R.compose(
toPromise,
R.ifElse(isEventEmpty, R.always({}), getPayload)
)
return processEvent(event)
}
module.exports = { handler }
With if (isEventEmpty(event)) {
coverage is 66.67% which is fine. But without that if
coverage will be 0. Notice that I use R.ifElse
composable from Ramda. All unit tests pass that's why I'm not showing them, but coverage report shows 0% Branches 0/1
. With imperative if
branch I have 2/3 in coverage report.
Does anyone have also experience NOT using if-else branching (or loops) when writing their code? Seems that nyc
is only looking in if-else, for/while branches or I might be wrong.