Created
July 10, 2014 10:46
-
-
Save Jeffy2012/c4286641c8c4f85584de to your computer and use it in GitHub Desktop.
Sinon.js Timer Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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