-
-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #317 from rwjblue/alternative-suggestion
Remove simple alias for `wait` -> `settled`.
- Loading branch information
Showing
4 changed files
with
65 additions
and
24 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,48 @@ | ||
export { | ||
default, | ||
_setupAJAXHooks, | ||
_setupPromiseListeners, | ||
_teardownAJAXHooks, | ||
_teardownPromiseListeners, | ||
} from '@ember/test-helpers/settled'; | ||
|
||
import { waitUntil, getSettledState } from '@ember/test-helpers'; | ||
|
||
/** | ||
Returns a promise that resolves when in a settled state (see `isSettled` for | ||
a definition of "settled state"). | ||
@private | ||
@deprecated | ||
@param {Object} [options={}] the options to be used for waiting | ||
@param {boolean} [options.waitForTimers=true] should timers be waited upon | ||
@param {boolean} [options.waitForAjax=true] should $.ajax requests be waited upon | ||
@param {boolean} [options.waitForWaiters=true] should test waiters be waited upon | ||
@returns {Promise<void>} resolves when settled | ||
*/ | ||
export default function wait(options = {}) { | ||
if (typeof options !== 'object' || options === null) { | ||
options = {}; | ||
} | ||
|
||
return waitUntil(() => { | ||
let waitForTimers = 'waitForTimers' in options ? options.waitForTimers : true; | ||
let waitForAJAX = 'waitForAJAX' in options ? options.waitForAJAX : true; | ||
let waitForWaiters = 'waitForWaiters' in options ? options.waitForWaiters : true; | ||
|
||
let { hasPendingTimers, hasRunLoop, hasPendingRequests, hasPendingWaiters } = getSettledState(); | ||
|
||
if (waitForTimers && (hasPendingTimers || hasRunLoop)) { | ||
return false; | ||
} | ||
|
||
if (waitForAJAX && hasPendingRequests) { | ||
return false; | ||
} | ||
|
||
if (waitForWaiters && hasPendingWaiters) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}); | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { module, test } from 'qunit'; | ||
import wait from 'ember-test-helpers/wait'; | ||
|
||
module('wait: unit tests', function() { | ||
test('issues a helpful assertion for invalid arguments', async function(assert) { | ||
assert.expect(0); // no assertions, just shouldn't error | ||
|
||
await wait(3000); | ||
await wait(null); | ||
await wait(); | ||
}); | ||
}); |