Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose isSettled utility function. #248

Merged
merged 1 commit into from
Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addon-test-support/@ember/test-helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export {
export { default as teardownContext } from './teardown-context';
export { default as setupRenderingContext, render, clearRender } from './setup-rendering-context';
export { default as teardownRenderingContext } from './teardown-rendering-context';
export { default as settled } from './settled';
export { default as settled, isSettled } from './settled';
export { default as validateErrorHandler } from './validate-error-handler';
52 changes: 32 additions & 20 deletions addon-test-support/@ember/test-helpers/settled.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,43 @@ function checkWaiters() {
return false;
}

export default function settled(_options) {
let options = _options || {};
let waitForTimers = options.hasOwnProperty('waitForTimers') ? options.waitForTimers : true;
let waitForAJAX = options.hasOwnProperty('waitForAJAX') ? options.waitForAJAX : true;
let waitForWaiters = options.hasOwnProperty('waitForWaiters') ? options.waitForWaiters : true;
export function isSettled(options) {
let waitForTimers = true;
let waitForAJAX = true;
let waitForWaiters = true;

if (options !== undefined) {
waitForTimers = 'waitForTimers' in options ? options.waitForTimers : true;
waitForAJAX = 'waitForAJAX' in options ? options.waitForAJAX : true;
waitForWaiters = 'waitForWaiters' in options ? options.waitForWaiters : true;
}

return new EmberPromise(function(resolve) {
let watcher = global.setInterval(function() {
if (waitForTimers && (run.hasScheduledTimers() || run.currentRunLoop)) {
return;
}
if (waitForTimers && (run.hasScheduledTimers() || run.currentRunLoop)) {
return false;
}

if (waitForAJAX && requests && requests.length > 0) {
return;
}
if (waitForAJAX && requests && requests.length > 0) {
return false;
}

if (waitForWaiters && checkWaiters()) {
return;
}
if (waitForWaiters && checkWaiters()) {
return false;
}

// Stop polling
global.clearInterval(watcher);
return true;
}

// Synchronously resolve the promise
run(null, resolve);
export default function settled(options) {
return new EmberPromise(function(resolve) {
let watcher = global.setInterval(function() {
let settled = isSettled(options);
if (settled) {
// Stop polling
global.clearInterval(watcher);

// Synchronously resolve the promise
run(null, resolve);
}
}, 10);
});
}