Mock clock now less intrusive, replacing global timer funcions only when clock is installed. [Fixes #54168708]

This commit is contained in:
Davis W. Frank
2013-08-27 22:46:01 -07:00
parent 2d4f398dd6
commit ba55cb5e38
6 changed files with 168 additions and 135 deletions

View File

@@ -13,18 +13,19 @@ getJasmineRequireObj().Clock = function() {
setInterval: setInterval,
clearInterval: clearInterval
},
timer = realTimingFunctions,
installed = false;
self.install = function() {
installed = true;
replace(global, fakeTimingFunctions);
timer = fakeTimingFunctions;
installed = true;
};
self.uninstall = function() {
delayedFunctionScheduler.reset();
installed = false;
replace(global, realTimingFunctions);
timer = realTimingFunctions;
installed = false;
};
self.setTimeout = function(fn, delay, params) {
@@ -59,7 +60,7 @@ getJasmineRequireObj().Clock = function() {
if (installed) {
delayedFunctionScheduler.tick(millis);
} else {
throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
throw new Error("Mock clock is not installed, use jasmine.getEnv().clock.install()");
}
};
@@ -69,7 +70,13 @@ getJasmineRequireObj().Clock = function() {
//if these methods are polyfilled, apply will be present
//TODO: it may be difficult to load the polyfill before jasmine loads
//(env should be new-ed inside of onload)
return !(global.setTimeout || global.setInterval).apply;
return !(realTimingFunctions.setTimeout || realTimingFunctions.setInterval).apply;
}
function replace(dest, source) {
for (var prop in source) {
dest[prop] = source[prop];
}
}
function setTimeout(fn, delay) {