sinon不会破坏财产价值

Wes*_*sty 7 stub sinon

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

sandbox.stub(myObject, 'hello').value('Sinon');
Run Code Online (Sandbox Code Playgroud)

但是,我收到错误:

"SinonStub"类型中不存在属性"值"

这样做的真正方法是什么?我浏览了所有可用的功能,并尝试过returnValue,但这也不是一个有效的功能.

以下是正在使用旧版本的sinon:

sandbox.stub(myObject, 'hello', 'Sinon');
Run Code Online (Sandbox Code Playgroud)

Jon*_*enn 12

这适用于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"
Run Code Online (Sandbox Code Playgroud)