Skip to content

Commit

Permalink
[BUGFIX beta] Avoid modifying setTimeout in run.later tests.
Browse files Browse the repository at this point in the history
(cherry picked from commit a168d44)
  • Loading branch information
rwjblue committed Feb 21, 2016
1 parent 2d4d14f commit ffb7c4f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/ember-metal/tests/run_loop/later_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import run from 'ember-metal/run_loop';

var originalSetTimeout = window.setTimeout;
var originalDateValueOf = Date.prototype.valueOf;
const originalPlatform = run.backburner._platform;

function wait(callback, maxWaitCount) {
maxWaitCount = isNone(maxWaitCount) ? 100 : maxWaitCount;
Expand Down Expand Up @@ -33,6 +34,7 @@ function pauseUntil(time) {

QUnit.module('run.later', {
teardown() {
run.backburner._platform = originalPlatform;
window.setTimeout = originalSetTimeout;
Date.prototype.valueOf = originalDateValueOf;
}
Expand Down Expand Up @@ -197,13 +199,14 @@ asyncTest('setTimeout should never run with a negative wait', function() {
// happens when an expired timer callback takes a while to run,
// which is what we simulate here.
var newSetTimeoutUsed;
window.setTimeout = function() {
var wait = arguments[arguments.length - 1];
newSetTimeoutUsed = true;
ok(!isNaN(wait) && wait >= 0, 'wait is a non-negative number');
// In IE8, `setTimeout.apply` is `undefined`.
var apply = Function.prototype.apply;
return apply.apply(originalSetTimeout, [this, arguments]);
run.backburner._platform = {
setTimeout() {
var wait = arguments[arguments.length - 1];
newSetTimeoutUsed = true;
ok(!isNaN(wait) && wait >= 0, 'wait is a non-negative number');

return originalPlatform.setTimeout.apply(originalPlatform, arguments);
}
};

var count = 0;
Expand All @@ -226,7 +229,6 @@ asyncTest('setTimeout should never run with a negative wait', function() {
});

wait(function() {
window.setTimeout = originalSetTimeout;
QUnit.start();
ok(newSetTimeoutUsed, 'stub setTimeout was used');
});
Expand Down

0 comments on commit ffb7c4f

Please sign in to comment.