Remove .sort() and fix logic in test

This commit is contained in:
Michael Leaney
2018-01-02 14:51:51 +08:00
parent 516e00d7ba
commit 1136fddcde
2 changed files with 11 additions and 11 deletions

View File

@@ -216,21 +216,23 @@ describe("DelayedFunctionScheduler", function() {
it("removes functions during a tick that runs the function", function() {
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn'),
spy = jasmine.createSpy('fn'),
spyAndRemove = jasmine.createSpy('fn'),
fnDelay = 10,
timeoutKey;
timeoutKey = scheduler.scheduleFunction(fn, fnDelay, [], true);
scheduler.scheduleFunction(function () {
spyAndRemove.and.callFake(function() {
scheduler.removeFunctionWithId(timeoutKey);
}, 2 * fnDelay);
});
expect(fn).not.toHaveBeenCalled();
scheduler.scheduleFunction(spyAndRemove, fnDelay);
scheduler.tick(3 * fnDelay);
timeoutKey = scheduler.scheduleFunction(spy, fnDelay, [], true);
expect(fn).toHaveBeenCalled();
expect(fn.calls.count()).toBe(2);
scheduler.tick(2 * fnDelay);
expect(spy).not.toHaveBeenCalled();
expect(spyAndRemove).toHaveBeenCalled();
});
it("removes functions during the first tick that runs the function", function() {

View File

@@ -129,9 +129,7 @@ getJasmineRequireObj().DelayedFunctionScheduler = function() {
currentTime = newCurrentTime;
var funcsToRun = scheduledFunctions[currentTime].sort(function (a, b) {
return a.millis > b.millis;
});
var funcsToRun = scheduledFunctions[currentTime];
delete scheduledFunctions[currentTime];