Skip to content

Instantly share code, notes, and snippets.

@machty
Created March 3, 2013 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save machty/5074333 to your computer and use it in GitHub Desktop.
Save machty/5074333 to your computer and use it in GitHub Desktop.
breaking test case from second +new Date()
test('setTimeout should never run with a negative wait', function() {
var originalSetTimeout = window.setTimeout, newSetTimeoutUsed;
window.setTimeout = function() {
var wait = arguments[arguments.length - 1];
newSetTimeoutUsed = true;
ok(!isNaN(wait) && wait >= 0, 'wait is a non-negative number');
if(wait < 0 ) {
debugger;
}
originalSetTimeout.apply(this, arguments);
};
var count = 0;
Ember.run(function() {
Ember.run.later(function() {
count++;
// This will get run first. Waste some time.
// This is intended to break invokeLaterTimers code by taking
// long enough time that other timers should technically. It's
// fine that they're not called in this run loop; just need to
// make sure that invokeLaterTimers doesn't end up scheduling
// a negative setTimeout.
var pauseUntil = +new Date() + 60;
while(+new Date() < pauseUntil) { /* do nothing - sleeping */ }
}, 1);
Ember.run.later(function() {
equal(count, 1, 'callbacks called in order');
}, 50);
});
stop();
originalSetTimeout(function() {
start();
ok(newSetTimeoutUsed, 'stub setTimeout was used');
// Restore setTimeout
window.setTimeout = originalSetTimeout;
}, 200);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment