gpt4 book ai didi

sinon 不 stub 属性值

转载 作者:行者123 更新时间:2023-12-04 10:34:37 33 4
gpt4 key购买 nike

我正在使用 sinon v4.1.2。根据文档( http://sinonjs.org/releases/v4.1.2/sandbox/ ),我应该能够使用以下内容设置属性:

sandbox.stub(myObject, 'hello').value('Sinon');

但是,我收到错误:

Property 'value' does not exist on type 'SinonStub'



这样做的真正方法是什么?我查看了所有可用的功能,并尝试了 returnValue ,但这也不是一个有效的函数。

以下是在旧版本的 sinon 上工作的:
sandbox.stub(myObject, 'hello', 'Sinon');

最佳答案

这适用于我的 Sinon.JS v4.1.2:

myObject = {hello: 'hello'}
sandbox = sinon.createSandbox()
sandbox.stub(myObject, 'hello').value('Sinon')
myObject.hello // "Sinon"
sandbox.restore()
myObject.hello // "hello"

关于sinon 不 stub 属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47424195/

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