docs/concepts/stubs/api/calls-arg-on-with.md
stub.callsArgOnWith(index, object)Causes the stub to call the argument at the provided index as a callback function, with the argument(s) provided and an additional object parameter to pass the this context.
import * as sinon from "sinon";
const person = {
name: "Mickey Mouse"
};
const stub = sinon
.stub()
.callsArgOnWith(0, person, "apple", "banana", "cherry");
function hello(first, second, third) {
console.log(this.name);
console.log(first, second, third);
}
stub(hello);
// => Mickey Mouse
// => apple banana cherry
When the argument at the provided index is not available or is not a function, an Error` will be thrown.
import * as sinon from "sinon";
const person = {
name: "Mickey Mouse"
};
const stub = sinon
.stub()
.callsArgOnWith(0, person, "apple", "banana", "cherry");
function hello(first, second, third) {
console.log(this.name);
console.log(first, second, third);
}
stub(undefined);
// => Uncaught TypeError: argument at index 0 is not a function: undefined