dimanche 28 février 2016

Ember component, how to wait for random jQuery plugin initialization?

I have an Ember component wrapping a random jQuery plugin.

setUp: on('didInsertElement', function() {
  scheduleOnce('afterRender', () => {
    this.$().datetimepicker();
  });
})

The plugin takes about 250ms to show up on screen, which causes me to write acceptance tests like so:

test('clicking toggles visibility', function(assert) {
  let done = assert.async();

  visit('/');

  andThen(function() {
    assert.strictEqual(find('.xdsoft_datetimepicker:visible', 'body').length, 0);
  });

  click('.xdsoft_datetimepicker');

  setTimeout(() => {
    andThen(function() {
      assert.strictEqual(find('.xdsoft_datetimepicker:visible', 'body').length, 1);
      done();
    });
  }, 500);
});

My goal is to alter the component so I can rely on the click test helper to block until the jQuery element is on screen. Something like didInsertElement or the run loop waiting for a promise that I can resolve once the element is on screen would be perfect. Does anything like this exist?




Aucun commentaire:

Enregistrer un commentaire