Skip to content

Instantly share code, notes, and snippets.

@rondale-sc
Created August 25, 2015 02:08
Show Gist options
  • Select an option

  • Save rondale-sc/6a55764e3dbb8dbdd09c to your computer and use it in GitHub Desktop.

Select an option

Save rondale-sc/6a55764e3dbb8dbdd09c to your computer and use it in GitHub Desktop.
import isNone from 'ember-metal/is_none';
import run from 'ember-metal/run_loop';
var originalSetTimeout = window.setTimeout;
var originalDateValueOf = Date.prototype.valueOf;
function wait(callback, maxWaitCount) {
maxWaitCount = isNone(maxWaitCount) ? 100 : maxWaitCount;
originalSetTimeout(function() {
if (maxWaitCount > 0 && (run.hasScheduledTimers() || run.currentRunLoop)) {
wait(callback, maxWaitCount - 1);
return;
}
callback();
}, 10);
}
QUnit.module('system/run_loop/scheduling_async', {
teardown() {
window.setTimeout = originalSetTimeout;
Date.prototype.valueOf = originalDateValueOf;
}
});
QUnit.asyncTest('test something', function(assert) {
var array = [];
run(function() {
run.later(function() {
array.push('later');
}, 100);
run.next(function() {
array.push('next');
});
});
wait(function() {
QUnit.start();
assert.deepEqual(array, ['next', 'later']);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment