Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sinon - create stub that returns own arguments

How can I make a stub that returns it's own arguments, like so:

var stub = sinon.stub().returns(???);

var result = stub('foo'); //result = foo

This will be nested so I can't return nothing and then check stub.getCall...

like image 443
Mankind1023 Avatar asked Feb 04 '23 01:02

Mankind1023


2 Answers

Try this

stub.returnsArg(0);

See docs

like image 121
Alex Avatar answered Feb 08 '23 10:02

Alex


Modify your code like below:

- var stub = sinon.stub().returns(???);
+ var stub = sinon.stub().returnsArg(0);

var result = stub('foo'); //result = foo
like image 28
aluc Avatar answered Feb 08 '23 12:02

aluc