Skip to content

Instantly share code, notes, and snippets.

@sarfata
Created May 9, 2013 19:06
Show Gist options
  • Save sarfata/5549732 to your computer and use it in GitHub Desktop.
Save sarfata/5549732 to your computer and use it in GitHub Desktop.
First test pass but the second one fails - I do not understand why. The only difference is that the second test ticks 200ms (which is more than needed), while the first one only ticks 100ms.
var assert = require('assert'),
sinon = require('sinon');
describe("Testing sinon useFakeTimers", function() {
it('sinon faking timer should work with small intervals', function() {
var clock = sinon.useFakeTimers();
var spy = sinon.spy();
setInterval(spy, 100);
assert(! spy.calledOnce);
clock.tick(101);
assert(spy.calledOnce);
clock.restore();
});
it('sinon faking timer should work with bigger intervals', function() {
var clock = sinon.useFakeTimers();
var spy = sinon.spy();
setInterval(spy, 100);
assert(! spy.calledOnce);
clock.tick(200);
assert(spy.calledOnce);
clock.restore();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment