Skip to content

Instantly share code, notes, and snippets.

@Jeffy2012
Created July 10, 2014 10:46
Show Gist options
  • Save Jeffy2012/c4286641c8c4f85584de to your computer and use it in GitHub Desktop.
Save Jeffy2012/c4286641c8c4f85584de to your computer and use it in GitHub Desktop.
Sinon.js Timer Demo
describe('timer Demo', function () {
var clock;
beforeEach(function () {
clock = sinon.useFakeTimers();
});
afterEach(function () {
clock.restore();
});
it('setTimeout', function () {
var spy = sinon.spy();
setTimeout(spy, 1000);
clock.tick(999);
expect(spy).to.not.be.called;
clock.tick(1);
expect(spy).to.be.called;
clock.tick(1100);
});
it("setInterval", function () {
var spy = sinon.spy();
setInterval(spy,1000);
clock.tick(999);
expect(spy).to.not.be.called;
clock.tick(1);
expect(spy).to.be.called;
clock.tick(5000);
expect(spy).to.have.callCount(6);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment