伊斯坦布尔代码覆盖率 - 如果未采用路径

Istanbul code coverage - if path is not taken

以下是找到随附的伊斯坦布尔覆盖率报告的函数。

export function getControlFromId(controlId, ancestorControl) {
  if (!(controlId && ancestorControl)) {
    return undefined;
  }
  if (controlId === ancestorControl.id) {
    return ancestorControl;
  }

  if (ancestorControl.controls) {
    for (const control of ancestorControl.controls) {
      const result = getControlFromId(controlId, control);
      if (result) {
        return result;
      }
    }
  }
  return undefined;
}

问题:为什么它说 if-path is not taken?该图像清楚地显示了执行 if 循环中的行。

样本测试数据:

const ancestorControl = {
        name: 'form',
        controls: [
          {
            name: 'Section',
            id: 1,
          },
        ],
      };

据我了解,这表明您的 if 条件已部分执行,这意味着您正在测试 ancestorControl.controls 可用的正向流。

您可能遗漏了 ancestorControl.controls 不可用的测试用例。