11

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

Mankind1023
  • 7,198
  • 16
  • 56
  • 86

2 Answers2

13

Try this

stub.returnsArg(0);

See docs

vsync
  • 118,978
  • 58
  • 307
  • 400
Alejandro
  • 5,834
  • 1
  • 19
  • 36
3

Modify your code like below:

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

var result = stub('foo'); //result = foo
vsync
  • 118,978
  • 58
  • 307
  • 400
Alfred
  • 1,276
  • 11
  • 19