Skip to content

Instantly share code, notes, and snippets.

@MarkBennett
Created March 9, 2013 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkBennett/5125780 to your computer and use it in GitHub Desktop.
Save MarkBennett/5125780 to your computer and use it in GitHub Desktop.
Instead of requiring that the first call to setInterval() be setInterval(animate, 1000/30) just require that a call be made once.
// ...snip.. from test.js:49
describe("setInterval", function() {
it("should have been called", function() {
setIntervalSpy.should.have.been.called;
});
it("with 'animate' as its first parameter", function() {
setIntervalSpy.should.have.been.calledWith(animate);
});
it("with second parameter equal to a framerate of 30 frames per second", function() {
var calls_to_animate_30_fps = 0;
setIntervalSpy.args.forEach(function(args) {
if (args[0] === animate && // we called animate
(args[1] - 1000/30) < 4 ) { // we set the timeout to within four milliseconds of 30 FPS
calls_to_animate_30_fps = calls_to_animate_30_fps + 1;
}
});
expect(calls_to_animate_30_fps).to.be.equalTo(1, "We expected your framerate passed to setInterval to be within 4 frames per second of 30 frames per second.\nHint: setInterval takes its arguments in milliseconds, and there are 1000 milliseconds in a second.\n\n");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment