DelayedFunctionScheduler tick, setTimeout/Interval delay defaults to 0
If ommited or null, delay for refered methods will default to 0. This will make setTimeout and setInterval methods to behave as expected by [HTML5 specs](http://www.w3.org/TR/html51/webappapis.html#timers): "Let timeout [delay] be the second argument to the method, or zero if the argument was omitted." This commit also fixes an issue with tick() being called without arguments, that causes the scheduler to break and stop working after this call.
This commit is contained in:
@@ -12,6 +12,19 @@ describe("DelayedFunctionScheduler", function() {
|
||||
expect(fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("defaults delay to 0", function() {
|
||||
var scheduler = new jasmine.DelayedFunctionScheduler(),
|
||||
fn = jasmine.createSpy('fn');
|
||||
|
||||
scheduler.scheduleFunction(fn);
|
||||
|
||||
expect(fn).not.toHaveBeenCalled();
|
||||
|
||||
scheduler.tick(0);
|
||||
|
||||
expect(fn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("optionally passes params to scheduled functions", function() {
|
||||
var scheduler = new jasmine.DelayedFunctionScheduler(),
|
||||
fn = jasmine.createSpy('fn');
|
||||
|
||||
@@ -5,11 +5,13 @@ jasmine.DelayedFunctionScheduler = function() {
|
||||
var delayedFnCount = 0;
|
||||
|
||||
self.tick = function(millis) {
|
||||
millis = millis || 0;
|
||||
runFunctionsWithinRange(currentTime, currentTime + millis);
|
||||
currentTime = currentTime + millis;
|
||||
};
|
||||
|
||||
self.scheduleFunction = function(funcToCall, millis, params, recurring, timeoutKey, runAtMillis) {
|
||||
millis = millis || 0;
|
||||
timeoutKey = timeoutKey || ++delayedFnCount;
|
||||
runAtMillis = runAtMillis || (currentTime + millis);
|
||||
scheduledFunctions[timeoutKey] = {
|
||||
|
||||
Reference in New Issue
Block a user