`waitUntil` async helper feedback


#1

I would like to get some feedback on the use of registerWaiter in an async helper to wait for animated components to appear.

In our acceptance tests, the waitUntil helper could be used as:

waitUntil('#my-button');
click('#my-button');

or

waitUntil('#my-modal.modal').then(function() {
  var el = find('#my-modal.modal');
  assert.ok(el.length > 0, 'modal was open');
  ....
});

Below the helper implementation:

Ember.Test.registerAsyncHelper('waitUntil', function(app, selector) {
  var waiter = function() {
    return $(selector).length > 0;
  };
  Ember.Test.registerWaiter(waiter);
  var promise = app.testHelpers.wait();
  promise.then(function() {
    Ember.Test.unregisterWaiter(waiter);
  });
  // it will be resolved when the pending events have been processed
  // (routing loads, ajax requests, run loops and waiters)
  return promise;

});

I think, this could be a common use of registerWaiter which could be added to the documentation.


Test Bootstrap Modal Open - setTimeout - async
#2
  1. What’s the callback param in the waiter function for?
  2. You should include some kind of timeout that fails if the selector elements never shows up.
  3. This should be fine if you’re only using it in acceptance test. Integration test should have components provide its own hooks on async.

#3

@lightblade thanks for the feedback.

  1. Including the callback parameter was an error. I have fixed it.
  2. timeout is a nice addition. I currently trust the QUnit.config.testTimeout for this purpose.
  3. Yes, it’s only used in acceptance test.

#4

nice idea.

some things I noticed.

if element is not found this causes an infinite loop.