admin管理员组文章数量:1293918
I am testing the function getAllOrdersOrderedByDateDescFindOptions
in my admin-find-options.helper.ts
file using Jest. The function includes ternary conditions to dynamically build a where clause based on searchOption
.
Even though my test cases pass and the function executes as expected (as seen in the logs), the test coverage report shows 86.66% branch coverage instead of 100%, specifically in lines 119-132.
Function being tested (simplified):
getAllOrdersOrderedByDateDescFindOptions(
searchOption: IPaginatedItems<ISearchOptionOrderAccountancy>,
): FindOptions<Order> {
let test = {};
console.log('je passe avant mon if');
if (searchOption.items.searchByPaymentMethod?.length) {
console.log('je passe ici');
test = {
'$paymentMethod.method$': {
[Op.in]: searchOption.items.searchByPaymentMethod,
},
};
}
return {
where: {
[Op.and]: [
test,
searchOption.items.searchByService?.length
? { '$service.name$': { [Op.in]: searchOption.items.searchByService } }
: {},
searchOption.items.searchByUser
? { [Op.or]: [{ '$user.nom$': { [Op.like]: `%${searchOption.items.searchByUser}%` } }] }
: {},
],
},
order: [['id', 'DESC']],
limit: searchOption.limit,
};
}
Logs confirm the ternary checks are being executed:
console.log(je passe avant mon if)
//Je passe avant mon if
console.log(je passe ici)
//je passe ici
Test coverage report:
src/admin/helper/admin-find-options.helper.ts | 100% Stmts | 86.66% Branch | 100% Funcs | 100% Lines | 119-132
Why does Jest report only 86.66% branch coverage when logs show the ternary conditions are executed?
How can I ensure 100% branch coverage for these ternary checks?
Do I need to write additional test cases for scenarios where searchOption.items.searchByPaymentMethod
is undefined or empty?
本文标签:
版权声明:本文标题:jestjs - Jest Test Coverage Missing for Ternary Conditions in getAllOrdersOrderedByDateDescFindOptions Function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741583548a2386711.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论