You can do a stub (or do) something based on the arguments invoked using .withArgs()and matching objects.
For example:
var sinon = require('sinon');
var anotherMethod = sinon.stub();
anotherMethod.withArgs(sinon.match({ key2 : true })) .returns('key2 was true');
anotherMethod.withArgs(sinon.match({ key2 : false })) .returns('key2 was false');
function method (obj) {
return anotherMethod({ key1 : 'val1', key2: obj.key3 });
}
console.log( method({ key3 : true }) );
console.log( method({ key3 : false }) );
More about matches here .
source
share