Created
March 3, 2013 03:19
-
-
Save machty/5074333 to your computer and use it in GitHub Desktop.
breaking test case from second +new Date()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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