Correctly handle functions that are scheduled after the clock is uninstalled and reinstalled from within Clock#tick.

Fixes #790.
This commit is contained in:
Steve Gravrock
2015-03-02 21:45:12 -08:00
parent abc0c4a97e
commit 2af9a45fb2
5 changed files with 52 additions and 75 deletions

View File

@@ -1,5 +1,5 @@
getJasmineRequireObj().Clock = function() {
function Clock(global, delayedFunctionScheduler, mockDate) {
function Clock(global, delayedFunctionSchedulerFactory, mockDate) {
var self = this,
realTimingFunctions = {
setTimeout: global.setTimeout,
@@ -14,19 +14,21 @@ getJasmineRequireObj().Clock = function() {
clearInterval: clearInterval
},
installed = false,
delayedFunctionScheduler,
timer;
self.install = function() {
replace(global, fakeTimingFunctions);
timer = fakeTimingFunctions;
delayedFunctionScheduler = delayedFunctionSchedulerFactory();
installed = true;
return self;
};
self.uninstall = function() {
delayedFunctionScheduler.reset();
delayedFunctionScheduler = null;
mockDate.uninstall();
replace(global, realTimingFunctions);

View File

@@ -72,13 +72,6 @@ getJasmineRequireObj().DelayedFunctionScheduler = function() {
}
};
self.reset = function() {
currentTime = 0;
scheduledLookup = [];
scheduledFunctions = {};
delayedFnCount = 0;
};
return self;
function indexOfFirstToPass(array, testFn) {

View File

@@ -11,7 +11,7 @@ getJasmineRequireObj().Env = function(j$) {
var realSetTimeout = j$.getGlobal().setTimeout;
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 runnableResources = {};