Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sinon not stubbing property value

Tags:

stub

sinon

I am using sinon v4.1.2. According to the documentation (http://sinonjs.org/releases/v4.1.2/sandbox/), I should be able to set a property using the following:

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

However, I am getting the error:

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

What is the real way to do this? I looked through all the available functions, and tried returnValue, but that isn't a valid function either.

The following was working on an older version of sinon:

sandbox.stub(myObject, 'hello', 'Sinon');
like image 529
Westy Avatar asked Nov 21 '17 23:11

Westy


1 Answers

This works for me with 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"
like image 184
Jonathan Benn Avatar answered Sep 21 '22 14:09

Jonathan Benn