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() { it("removes functions during a tick that runs the function", function() {
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(), var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn'), spy = jasmine.createSpy('fn'),
spyAndRemove = jasmine.createSpy('fn'),
fnDelay = 10, fnDelay = 10,
timeoutKey; timeoutKey;
timeoutKey = scheduler.scheduleFunction(fn, fnDelay, [], true); spyAndRemove.and.callFake(function() {
scheduler.scheduleFunction(function () {
scheduler.removeFunctionWithId(timeoutKey); 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(); scheduler.tick(2 * fnDelay);
expect(fn.calls.count()).toBe(2);
expect(spy).not.toHaveBeenCalled();
expect(spyAndRemove).toHaveBeenCalled();
}); });
it("removes functions during the first tick that runs the function", function() { it("removes functions during the first tick that runs the function", function() {

View File

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