Created
August 25, 2015 02:08
-
-
Save rondale-sc/6a55764e3dbb8dbdd09c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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