Merge pull request #340 from CaioToOn/fix-clock-settimeout
DelayedFunctionScheduler tick, setTimeout/Interval delay defaults to 0
This commit is contained in:
@@ -12,6 +12,32 @@ describe("DelayedFunctionScheduler", function() {
|
|||||||
expect(fn).toHaveBeenCalled();
|
expect(fn).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("#tick defaults to 0", function() {
|
||||||
|
var scheduler = new jasmine.DelayedFunctionScheduler(),
|
||||||
|
fn = jasmine.createSpy('fn');
|
||||||
|
|
||||||
|
scheduler.scheduleFunction(fn, 0);
|
||||||
|
|
||||||
|
expect(fn).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
scheduler.tick();
|
||||||
|
|
||||||
|
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() {
|
it("optionally passes params to scheduled functions", function() {
|
||||||
var scheduler = new jasmine.DelayedFunctionScheduler(),
|
var scheduler = new jasmine.DelayedFunctionScheduler(),
|
||||||
fn = jasmine.createSpy('fn');
|
fn = jasmine.createSpy('fn');
|
||||||
|
|||||||
@@ -5,11 +5,13 @@ jasmine.DelayedFunctionScheduler = function() {
|
|||||||
var delayedFnCount = 0;
|
var delayedFnCount = 0;
|
||||||
|
|
||||||
self.tick = function(millis) {
|
self.tick = function(millis) {
|
||||||
|
millis = millis || 0;
|
||||||
runFunctionsWithinRange(currentTime, currentTime + millis);
|
runFunctionsWithinRange(currentTime, currentTime + millis);
|
||||||
currentTime = currentTime + millis;
|
currentTime = currentTime + millis;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.scheduleFunction = function(funcToCall, millis, params, recurring, timeoutKey, runAtMillis) {
|
self.scheduleFunction = function(funcToCall, millis, params, recurring, timeoutKey, runAtMillis) {
|
||||||
|
millis = millis || 0;
|
||||||
timeoutKey = timeoutKey || ++delayedFnCount;
|
timeoutKey = timeoutKey || ++delayedFnCount;
|
||||||
runAtMillis = runAtMillis || (currentTime + millis);
|
runAtMillis = runAtMillis || (currentTime + millis);
|
||||||
scheduledFunctions[timeoutKey] = {
|
scheduledFunctions[timeoutKey] = {
|
||||||
|
|||||||
Reference in New Issue
Block a user