Correctly handle functions that are scheduled after the clock is uninstalled and reinstalled from within Clock#tick.
Fixes #790.
This commit is contained in:
+47
-24
@@ -6,7 +6,7 @@ describe("Clock", function() {
|
|||||||
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction"]),
|
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction"]),
|
||||||
delayedFn = jasmine.createSpy("delayedFn"),
|
delayedFn = jasmine.createSpy("delayedFn"),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
|
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
||||||
|
|
||||||
fakeGlobal.setTimeout(delayedFn, 0);
|
fakeGlobal.setTimeout(delayedFn, 0);
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ describe("Clock", function() {
|
|||||||
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["removeFunctionWithId"]),
|
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["removeFunctionWithId"]),
|
||||||
delayedFn = jasmine.createSpy("delayedFn"),
|
delayedFn = jasmine.createSpy("delayedFn"),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
|
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
||||||
|
|
||||||
fakeGlobal.clearTimeout("foo");
|
fakeGlobal.clearTimeout("foo");
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ describe("Clock", function() {
|
|||||||
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction"]),
|
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction"]),
|
||||||
delayedFn = jasmine.createSpy("delayedFn"),
|
delayedFn = jasmine.createSpy("delayedFn"),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
|
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
||||||
|
|
||||||
fakeGlobal.setInterval(delayedFn, 0);
|
fakeGlobal.setInterval(delayedFn, 0);
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ describe("Clock", function() {
|
|||||||
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["removeFunctionWithId"]),
|
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["removeFunctionWithId"]),
|
||||||
delayedFn = jasmine.createSpy("delayedFn"),
|
delayedFn = jasmine.createSpy("delayedFn"),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
|
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
||||||
|
|
||||||
fakeGlobal.clearInterval("foo");
|
fakeGlobal.clearInterval("foo");
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ describe("Clock", function() {
|
|||||||
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction", "reset"]),
|
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction", "reset"]),
|
||||||
delayedFn = jasmine.createSpy("delayedFn"),
|
delayedFn = jasmine.createSpy("delayedFn"),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
|
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
||||||
|
|
||||||
clock.install();
|
clock.install();
|
||||||
clock.uninstall();
|
clock.uninstall();
|
||||||
@@ -132,7 +132,7 @@ describe("Clock", function() {
|
|||||||
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction", "reset", "removeFunctionWithId"]),
|
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction", "reset", "removeFunctionWithId"]),
|
||||||
delayedFn = jasmine.createSpy("delayedFn"),
|
delayedFn = jasmine.createSpy("delayedFn"),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate),
|
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
|
||||||
passedFunctionCalled = false;
|
passedFunctionCalled = false;
|
||||||
|
|
||||||
clock.withMock(function() {
|
clock.withMock(function() {
|
||||||
@@ -179,7 +179,7 @@ describe("Clock", function() {
|
|||||||
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction", "reset", "removeFunctionWithId"]),
|
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction", "reset", "removeFunctionWithId"]),
|
||||||
delayedFn = jasmine.createSpy("delayedFn"),
|
delayedFn = jasmine.createSpy("delayedFn"),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate),
|
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
|
||||||
passedFunctionCalled = false;
|
passedFunctionCalled = false;
|
||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
@@ -222,7 +222,7 @@ describe("Clock", function() {
|
|||||||
fakeGlobal = { setTimeout: fakeSetTimeout },
|
fakeGlobal = { setTimeout: fakeSetTimeout },
|
||||||
delayedFn = jasmine.createSpy('delayedFn'),
|
delayedFn = jasmine.createSpy('delayedFn'),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
|
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
||||||
|
|
||||||
clock.install();
|
clock.install();
|
||||||
clock.setTimeout(delayedFn, 0, 'a', 'b');
|
clock.setTimeout(delayedFn, 0, 'a', 'b');
|
||||||
@@ -239,7 +239,7 @@ describe("Clock", function() {
|
|||||||
fakeGlobal = { setTimeout: fakeSetTimeout },
|
fakeGlobal = { setTimeout: fakeSetTimeout },
|
||||||
delayedFn = jasmine.createSpy('delayedFn'),
|
delayedFn = jasmine.createSpy('delayedFn'),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate),
|
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
|
||||||
timeoutId;
|
timeoutId;
|
||||||
|
|
||||||
clock.install();
|
clock.install();
|
||||||
@@ -254,7 +254,7 @@ describe("Clock", function() {
|
|||||||
fakeGlobal = { setTimeout: fakeClearTimeout },
|
fakeGlobal = { setTimeout: fakeClearTimeout },
|
||||||
delayedFn = jasmine.createSpy('delayedFn'),
|
delayedFn = jasmine.createSpy('delayedFn'),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
|
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
||||||
|
|
||||||
clock.install();
|
clock.install();
|
||||||
clock.clearTimeout(123);
|
clock.clearTimeout(123);
|
||||||
@@ -270,7 +270,7 @@ describe("Clock", function() {
|
|||||||
fakeGlobal = { setInterval: fakeSetInterval },
|
fakeGlobal = { setInterval: fakeSetInterval },
|
||||||
delayedFn = jasmine.createSpy('delayedFn'),
|
delayedFn = jasmine.createSpy('delayedFn'),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
|
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
||||||
|
|
||||||
clock.install();
|
clock.install();
|
||||||
clock.setInterval(delayedFn, 0, 'a', 'b');
|
clock.setInterval(delayedFn, 0, 'a', 'b');
|
||||||
@@ -287,7 +287,7 @@ describe("Clock", function() {
|
|||||||
fakeGlobal = { setInterval: fakeSetInterval },
|
fakeGlobal = { setInterval: fakeSetInterval },
|
||||||
delayedFn = jasmine.createSpy('delayedFn'),
|
delayedFn = jasmine.createSpy('delayedFn'),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate),
|
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
|
||||||
intervalId;
|
intervalId;
|
||||||
|
|
||||||
clock.install();
|
clock.install();
|
||||||
@@ -302,7 +302,7 @@ describe("Clock", function() {
|
|||||||
fakeGlobal = { setInterval: clearInterval },
|
fakeGlobal = { setInterval: clearInterval },
|
||||||
delayedFn = jasmine.createSpy('delayedFn'),
|
delayedFn = jasmine.createSpy('delayedFn'),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
|
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
||||||
|
|
||||||
clock.install();
|
clock.install();
|
||||||
clock.clearInterval(123);
|
clock.clearInterval(123);
|
||||||
@@ -329,7 +329,7 @@ describe("Clock", function() {
|
|||||||
setInterval: fakeSetInterval
|
setInterval: fakeSetInterval
|
||||||
},
|
},
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler, mockDate);
|
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
||||||
|
|
||||||
fakeSetTimeout.apply = null;
|
fakeSetTimeout.apply = null;
|
||||||
fakeSetInterval.apply = null;
|
fakeSetInterval.apply = null;
|
||||||
@@ -348,7 +348,6 @@ describe("Clock", function() {
|
|||||||
clock.setInterval(fn, 0, 'extra');
|
clock.setInterval(fn, 0, 'extra');
|
||||||
}).toThrow();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Clock (acceptance)", function() {
|
describe("Clock (acceptance)", function() {
|
||||||
@@ -359,7 +358,7 @@ describe("Clock (acceptance)", function() {
|
|||||||
recurring1 = jasmine.createSpy('recurring1'),
|
recurring1 = jasmine.createSpy('recurring1'),
|
||||||
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock({setTimeout: setTimeout}, delayedFunctionScheduler, mockDate);
|
clock = new j$.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate);
|
||||||
|
|
||||||
clock.install();
|
clock.install();
|
||||||
|
|
||||||
@@ -406,7 +405,7 @@ describe("Clock (acceptance)", function() {
|
|||||||
var clearedFn = jasmine.createSpy('clearedFn'),
|
var clearedFn = jasmine.createSpy('clearedFn'),
|
||||||
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock({setTimeout: function() {}}, delayedFunctionScheduler, mockDate),
|
clock = new j$.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate),
|
||||||
timeoutId;
|
timeoutId;
|
||||||
|
|
||||||
clock.install();
|
clock.install();
|
||||||
@@ -424,7 +423,7 @@ describe("Clock (acceptance)", function() {
|
|||||||
var spy = jasmine.createSpy('spy'),
|
var spy = jasmine.createSpy('spy'),
|
||||||
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock({setInterval: function() {}}, delayedFunctionScheduler, mockDate),
|
clock = new j$.Clock({setInterval: function() {}}, function () { return delayedFunctionScheduler; }, mockDate),
|
||||||
intervalId;
|
intervalId;
|
||||||
|
|
||||||
clock.install();
|
clock.install();
|
||||||
@@ -442,7 +441,7 @@ describe("Clock (acceptance)", function() {
|
|||||||
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||||
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock({setTimeout: function() {}}, delayedFunctionScheduler, mockDate);
|
clock = new j$.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate);
|
||||||
|
|
||||||
clock.install();
|
clock.install();
|
||||||
|
|
||||||
@@ -459,7 +458,7 @@ describe("Clock (acceptance)", function() {
|
|||||||
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
||||||
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock({setTimeout: function() {}}, delayedFunctionScheduler, mockDate);
|
clock = new j$.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate);
|
||||||
|
|
||||||
delayedFn1.and.callFake(function() { clock.setTimeout(delayedFn2, 0); });
|
delayedFn1.and.callFake(function() { clock.setTimeout(delayedFn2, 0); });
|
||||||
clock.install();
|
clock.install();
|
||||||
@@ -478,7 +477,7 @@ describe("Clock (acceptance)", function() {
|
|||||||
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
||||||
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
||||||
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
clock = new j$.Clock({setTimeout: function() {}}, delayedFunctionScheduler, mockDate);
|
clock = new j$.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate);
|
||||||
|
|
||||||
delayedFn1.and.callFake(function() { clock.setTimeout(delayedFn2, 1); });
|
delayedFn1.and.callFake(function() { clock.setTimeout(delayedFn2, 1); });
|
||||||
clock.install();
|
clock.install();
|
||||||
@@ -489,11 +488,35 @@ describe("Clock (acceptance)", function() {
|
|||||||
expect(delayedFn2).toHaveBeenCalled();
|
expect(delayedFn2).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("correctly schedules functions scheduled while the Clock is advancing but after the Clock is uninstalled", function() {
|
||||||
|
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
||||||
|
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
||||||
|
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
||||||
|
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
||||||
|
clock = new j$.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate);
|
||||||
|
|
||||||
|
delayedFn1.and.callFake(function() {
|
||||||
|
clock.uninstall();
|
||||||
|
clock.install();
|
||||||
|
clock.setTimeout(delayedFn2, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
clock.install();
|
||||||
|
clock.setTimeout(delayedFn1, 1);
|
||||||
|
|
||||||
|
clock.tick(1);
|
||||||
|
expect(delayedFn1).toHaveBeenCalled();
|
||||||
|
expect(delayedFn2).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
clock.tick(1);
|
||||||
|
expect(delayedFn2).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it("does not mock the Date object by default", function() {
|
it("does not mock the Date object by default", function() {
|
||||||
var delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
var delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
||||||
global = {Date: Date},
|
global = {Date: Date},
|
||||||
mockDate = new j$.MockDate(global),
|
mockDate = new j$.MockDate(global),
|
||||||
clock = new j$.Clock({setTimeout: setTimeout}, delayedFunctionScheduler, mockDate);
|
clock = new j$.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate);
|
||||||
|
|
||||||
clock.install();
|
clock.install();
|
||||||
|
|
||||||
@@ -510,7 +533,7 @@ describe("Clock (acceptance)", function() {
|
|||||||
var delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
var delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
||||||
global = {Date: Date},
|
global = {Date: Date},
|
||||||
mockDate = new j$.MockDate(global),
|
mockDate = new j$.MockDate(global),
|
||||||
clock = new j$.Clock({setTimeout: setTimeout}, delayedFunctionScheduler, mockDate);
|
clock = new j$.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate);
|
||||||
|
|
||||||
clock.install().mockDate();
|
clock.install().mockDate();
|
||||||
|
|
||||||
@@ -534,7 +557,7 @@ describe("Clock (acceptance)", function() {
|
|||||||
var delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
var delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
|
||||||
global = {Date: Date},
|
global = {Date: Date},
|
||||||
mockDate = new j$.MockDate(global),
|
mockDate = new j$.MockDate(global),
|
||||||
clock = new j$.Clock({setTimeout: setTimeout}, delayedFunctionScheduler, mockDate),
|
clock = new j$.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate),
|
||||||
baseTime = new Date(2013, 9, 23);
|
baseTime = new Date(2013, 9, 23);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -113,47 +113,6 @@ describe("DelayedFunctionScheduler", function() {
|
|||||||
expect(fn).not.toHaveBeenCalled();
|
expect(fn).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reset removes scheduled functions", function() {
|
|
||||||
var scheduler = new j$.DelayedFunctionScheduler(),
|
|
||||||
fn = jasmine.createSpy('fn');
|
|
||||||
|
|
||||||
scheduler.scheduleFunction(fn, 0);
|
|
||||||
|
|
||||||
expect(fn).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
scheduler.reset();
|
|
||||||
|
|
||||||
scheduler.tick(0);
|
|
||||||
|
|
||||||
expect(fn).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("reset resets the returned ids", function() {
|
|
||||||
var scheduler = new j$.DelayedFunctionScheduler();
|
|
||||||
expect(scheduler.scheduleFunction(function() { }, 0)).toBe(1);
|
|
||||||
expect(scheduler.scheduleFunction(function() { }, 0, [], false, 123)).toBe(123);
|
|
||||||
|
|
||||||
scheduler.reset();
|
|
||||||
expect(scheduler.scheduleFunction(function() { }, 0)).toBe(1);
|
|
||||||
expect(scheduler.scheduleFunction(function() { }, 0, [], false, 123)).toBe(123);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("reset resets the current tick time", function() {
|
|
||||||
var scheduler = new j$.DelayedFunctionScheduler(),
|
|
||||||
fn = jasmine.createSpy('fn');
|
|
||||||
|
|
||||||
expect(fn).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
scheduler.tick(15);
|
|
||||||
scheduler.reset();
|
|
||||||
|
|
||||||
scheduler.scheduleFunction(fn, 20, [], false, 1, 20);
|
|
||||||
|
|
||||||
scheduler.tick(5);
|
|
||||||
|
|
||||||
expect(fn).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("executes recurring functions interleaved with regular functions in the correct order", function() {
|
it("executes recurring functions interleaved with regular functions in the correct order", function() {
|
||||||
var scheduler = new j$.DelayedFunctionScheduler(),
|
var scheduler = new j$.DelayedFunctionScheduler(),
|
||||||
fn = jasmine.createSpy('fn'),
|
fn = jasmine.createSpy('fn'),
|
||||||
|
|||||||
+4
-2
@@ -1,5 +1,5 @@
|
|||||||
getJasmineRequireObj().Clock = function() {
|
getJasmineRequireObj().Clock = function() {
|
||||||
function Clock(global, delayedFunctionScheduler, mockDate) {
|
function Clock(global, delayedFunctionSchedulerFactory, mockDate) {
|
||||||
var self = this,
|
var self = this,
|
||||||
realTimingFunctions = {
|
realTimingFunctions = {
|
||||||
setTimeout: global.setTimeout,
|
setTimeout: global.setTimeout,
|
||||||
@@ -14,19 +14,21 @@ getJasmineRequireObj().Clock = function() {
|
|||||||
clearInterval: clearInterval
|
clearInterval: clearInterval
|
||||||
},
|
},
|
||||||
installed = false,
|
installed = false,
|
||||||
|
delayedFunctionScheduler,
|
||||||
timer;
|
timer;
|
||||||
|
|
||||||
|
|
||||||
self.install = function() {
|
self.install = function() {
|
||||||
replace(global, fakeTimingFunctions);
|
replace(global, fakeTimingFunctions);
|
||||||
timer = fakeTimingFunctions;
|
timer = fakeTimingFunctions;
|
||||||
|
delayedFunctionScheduler = delayedFunctionSchedulerFactory();
|
||||||
installed = true;
|
installed = true;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.uninstall = function() {
|
self.uninstall = function() {
|
||||||
delayedFunctionScheduler.reset();
|
delayedFunctionScheduler = null;
|
||||||
mockDate.uninstall();
|
mockDate.uninstall();
|
||||||
replace(global, realTimingFunctions);
|
replace(global, realTimingFunctions);
|
||||||
|
|
||||||
|
|||||||
@@ -72,13 +72,6 @@ getJasmineRequireObj().DelayedFunctionScheduler = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.reset = function() {
|
|
||||||
currentTime = 0;
|
|
||||||
scheduledLookup = [];
|
|
||||||
scheduledFunctions = {};
|
|
||||||
delayedFnCount = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
||||||
function indexOfFirstToPass(array, testFn) {
|
function indexOfFirstToPass(array, testFn) {
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
|
|
||||||
var realSetTimeout = j$.getGlobal().setTimeout;
|
var realSetTimeout = j$.getGlobal().setTimeout;
|
||||||
var realClearTimeout = j$.getGlobal().clearTimeout;
|
var realClearTimeout = j$.getGlobal().clearTimeout;
|
||||||
this.clock = new j$.Clock(global, new j$.DelayedFunctionScheduler(), new j$.MockDate(global));
|
this.clock = new j$.Clock(global, function () { return new j$.DelayedFunctionScheduler(); }, new j$.MockDate(global));
|
||||||
|
|
||||||
var runnableLookupTable = {};
|
var runnableLookupTable = {};
|
||||||
var runnableResources = {};
|
var runnableResources = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user