gpt4 book ai didi

jestjs - 用 Jest 和 Enzyme 覆盖空操作函数

转载 作者:行者123 更新时间:2023-12-05 06:23:35 25 4
gpt4 key购买 nike

在我的 React 组件中,我有一些无操作函数,它们基本上只是函数的占位符。我有 Istanbul 尔测试覆盖率,它提示无操作功能覆盖率: 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,
}

关于jestjs - 用 Jest 和 Enzyme 覆盖空操作函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58219338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com