I'd like to see such a change, and I can't think of any harm offhand.
In the meantime, in case it helps anyone, what I normally do as a workaround is to have a method wrapping the thing I want to control, such as Math.random, and then I mock that instead. For example,
(function() {
test('mocking Math.random', function() {
function ProductionClass() {}
ProductionClass.prototype.call_random = function(min, max) {
if ((undefined === min) || (undefined === max)) {
return Math.random();
}
return Math.random() * (max - min) + min;
};
// Setup
var test_me = new ProductionClass,
mock_test_me = sinon.mock(test_me);
mock_test_me.expects('call_random').withExactArgs(0,10).returns(0);
mock_test_me.expects('call_random').withExactArgs(0,10).returns(1);
mock_test_me.expects('call_random').withExactArgs(0,10).returns(2);
// Code under test
console.log(test_me.call_random(0,10)); // 0
console.log(test_me.call_random(0,10)); // 1
console.log(test_me.call_random(0,10)); // 2
// Assert
mock_test_me.verify();
});
}());