Mock clock now less intrusive, replacing global timer funcions only when clock is installed. [Fixes #54168708]
This commit is contained in:
@@ -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()
|
||||
})
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user