Reputation: 110
Protractor provides a great API wrapper around selenium-webdriver tests, but one of the ways it does that is by using a hook that Angular provides to denote the completion of all outstanding async/polling operations. This includes http calls, intervals, etc.
I'm fairly new to Ember, but I suspect the equivalent would need to be aware of route changes, http calls, and one or more aspects of the run loop. I've confirmed that such a hook would likely open the door to using Protractor with Ember apps, which is ultimately my goal.
So, is there a way to detect when Ember has entered this "quiet" state?
Upvotes: 3
Views: 710
Reputation: 47367
Here's how Ember does it (only in test mode, and Test is available on the Ember namespace)
function wait(app, value) {
return Test.promise(function(resolve) {
// If this is the first async promise, kick off the async test
if (++countAsync === 1) {
Test.adapter.asyncStart();
}
// Every 10ms, poll for the async thing to have finished
var watcher = setInterval(function() {
// 1. If the router is loading, keep polling
var routerIsLoading = !!app.__container__.lookup('router:main').router.activeTransition;
if (routerIsLoading) { return; }
// 2. If there are pending Ajax requests, keep polling
if (Test.pendingAjaxRequests) { return; }
// 3. If there are scheduled timers or we are inside of a run loop, keep polling
if (run.hasScheduledTimers() || run.currentRunLoop) { return; }
if (Test.waiters && Test.waiters.any(function(waiter) {
var context = waiter[0];
var callback = waiter[1];
return !callback.call(context);
})) { return; }
// Stop polling
clearInterval(watcher);
// If this is the last async promise, end the async test
if (--countAsync === 0) {
Test.adapter.asyncEnd();
}
// Synchronously resolve the promise
run(null, resolve, value);
}, 10);
});
}
Upvotes: 1