【发布时间】:2020-11-23 08:03:34
【问题描述】:
我想跳过第二个 if 语句
在测试时,我不会通过任何“用户 ID”,因此我想跳过第二个 if。
async update(id: string, userid: string, input: UpdateNotificationInput) {
const items = await this.model.query('id').eq(id).exec();
if (items.length === 1) {
/* istanbul ignore if */
if (items[0].userId !== userid) {
throw new BadRequestException();
}
const { appTargetId, createDate } = items[0];
return await this.model.update({ appTargetId, createDate }, input);
} else {
throw new BadRequestException();
}
}
下面的 if 不应该被访问。
if (items[0].userId !== userid) {
throw new BadRequestException();
}
我的“istanbul ignore if”或“istanbul ignore next”似乎不起作用。
当我运行我的测试覆盖率时,访问了 if 语句并出现错误。
我是否以正确的方式使用它?
【问题讨论】:
-
对于像我一样想知道“伊斯坦布尔”是什么的人:github.com/gotwarlost/istanbul/blob/master/…
标签: javascript typescript jestjs istanbul