Remove .sort() and fix logic in test
This commit is contained in:
@@ -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() {
|
||||||
|
|||||||
@@ -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];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user