用笑话和酶覆盖无操作功能

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用笑话和酶覆盖无操作功能相关的知识,希望对你有一定的参考价值。

在我的React组件中,我有一些no-op函数,它们基本上只是一个函数的占位符。我拥有伊斯坦布尔测试报道,并且抱怨无操作功能报道:enter image description here

有什么办法掩盖吗?

答案

为了使Instanbul忽略noop函数,我们可以使用/* istanbul ignore next */中提到的here

例如,您可以做类似的事情

const defaultContext = {
  activeInput: null,
  removeFocus: /* istanbul ignore next */ () => {},
  focusInput: /* istanbul ignore next */ () => {},
}

或者您可以定义一个隔离的noop函数并在需要时重用

/* istanbul ignore next */
function noop() {}

const defaultContext = {
  activeInput: null,
  removeFocus: noop,
  focusInput: noop,
}

以上是关于用笑话和酶覆盖无操作功能的主要内容,如果未能解决你的问题,请参考以下文章