cjohansen/Sinon.JS — Issue #58: About stub.callsArg throws error if the arg is not callable
Author: gravof
Created: 2011-11-19 06:22:24+00:00
State: open

Sometimes I wish stub.callsArg would not throw error if the arg is not callable. For example:

If I have this obj:

```javascript
obj = {
data: 1,

isDataValid: function(valid, invalid) {
// Async method that calls its first arg if data is valid otherwise calls its second
},

processData: function() {
this.isDataValid(function() {
++this.data;
});
}
}
```

And I'd like to make sure that if data isn't valid, it's not processed

```javascript
sinon.stub(obj, 'isDataValid');
obj.isDataValid.callsArg(1);
obj.processData();
assertEqual(obj.data, 1);
```

It apparently doesn't work because `obj.processData()` will throw error.

It would be great if there exists a stub API that calls the arg *only if* it's callable. Do you think it's possible? If it is, should we modify `stub.callsArg()` or introduce a new API? What would the new API be?