Mankind1023
Mankind1023

Reputation: 7732

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...

Upvotes: 12

Views: 5882

Answers (2)

Sasha
Sasha

Reputation: 5944

Try this

stub.returnsArg(0);

See docs

Upvotes: 13

Alfred
Alfred

Reputation: 1296

Modify your code like below:

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

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

Upvotes: 3

Related Questions