Clear timeouts when starting to process a milli instead of at the end

- Fixes #1482
This commit is contained in:
Gregg Van Hove
2018-01-19 17:47:28 -08:00
parent c82e5947f5
commit 53529bdc9a
2 changed files with 17 additions and 1 deletions

View File

@@ -254,6 +254,22 @@ describe("DelayedFunctionScheduler", function() {
expect(fn.calls.count()).toBe(1);
});
it("does not remove a function that hasn't been added yet", function() {
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn'),
fnDelay = 10,
timeoutKey;
scheduler.removeFunctionWithId('foo');
scheduler.scheduleFunction(fn, fnDelay, [], false, 'foo');
expect(fn).not.toHaveBeenCalled();
scheduler.tick(fnDelay + 1);
expect(fn).toHaveBeenCalled();
});
it("updates the mockDate per scheduled time", function () {
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
tickDate = jasmine.createSpy('tickDate');

View File

@@ -124,6 +124,7 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
}
do {
deletedKeys = [];
var newCurrentTime = scheduledLookup.shift();
tickDate(newCurrentTime - currentTime);
@@ -146,7 +147,6 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) {
}
funcToRun.funcToCall.apply(null, funcToRun.params || []);
});
deletedKeys = [];
} while (scheduledLookup.length > 0 &&
// checking first if we're out of time prevents setTimeout(0)
// scheduled in a funcToRun from forcing an extra iteration