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

@@ -69,10 +69,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
},
clock: env.clock,
setTimeout: env.clock.setTimeout,
clearTimeout: env.clock.clearTimeout,
setInterval: env.clock.setInterval,
clearInterval: env.clock.clearInterval,
jsApiReporter: new jasmine.JsApiReporter({
timer: new jasmine.Timer()
})

View File

@@ -47,10 +47,6 @@
},
clock: env.clock,
setTimeout: env.clock.setTimeout,
clearTimeout: env.clock.clearTimeout,
setInterval: env.clock.setInterval,
clearInterval: env.clock.clearInterval,
jsApiReporter: new jasmine.JsApiReporter({
timer: new jasmine.Timer()
})

View File

@@ -889,18 +889,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) {
@@ -935,7 +936,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()");
}
};
@@ -945,7 +946,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) {