I have a function that will select a random value between a min and a max value. So when I have a test where I test that the value fall between the min and max value. But as
SinonJS is a JavaScript mocking framework which integrates with all of the major JavaScript Unit Testing frameworks. The adapters will take care of 'reverting' any stubs / mocks that you create during your tests.
// Stub out Math.random so it always returns '4' (chosen by fair dice roll)
sinon.stub(Math, 'random').returns(4);
// Double check that it worked.
equal(Math.random(), 4, "http://xkcd.com/221/");