Created
March 9, 2013 21:14
-
-
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.
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
// ...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