Seriously, I can't figure this out. The documentation gives us:
stub.callsArg(index) - Causes the stub to call the argument at the provided index as a callback function. stub.callsArg(0); causes the stub to call the first argument as a callback.
However, I've got no idea where this list of arguments to be indexed into is. Maybe I just don't understand what a stub is...
A stub is a noop function with programmable behavior. In your case callsArg(index)
will program the stub to expect a function at index
and immediately invoke it.
function sayHi() {
console.log('hi');
}
var stub = sinon.stub().callsArg(2);
stub('abc', 42, sayHi); // prints "hi"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With