I'd like to create a conditional stub that invokes a function when called, but it appears that this feature doesn't exist. For example:
var jQuery = sinon.stub();
jQuery.invokes(function(selection) { return new JQuerySelection(selection); });
jQuery.withArgs('.foo').returns(fooObj);
I see that I can stub with a function using sinon.stub(object, 'method', function() { ... }), but this actually returns a spy instead of a stub instance. So this doesn't work, for example:
var dummy = { jQuery: function() { } };
var jQuery = sinon.stub(dummy, 'jQuery', function(selection) { return new JQuerySelection(selection); });
jQuery.withArgs('.foo').returns(fooObj); // Error... no returns method
Am I missing something in the API, or is this just not possible with Sinon?
--
Jacob