mock method calling callback function sinon
sinon.stub(a, 'getText').yields(null, 'a string');
yields()
will call the first function argument that gets passed to the stubbed function with the arguments provided (null, 'a string'
).
You can use callsArgWith
sinon.stub(a, 'getText').callsArgWith(1, null, 'a string')
let cb = function(err, response) {
console.log(response); // 'a string'
}
a.getText('abc', cb)