vendredi 3 juin 2016

Why does ember.run call finish before work scheduled by ember.run.later completes?

According to the docs for Ember.run it:

Runs the passed target and method inside of a RunLoop, ensuring any deferred actions including bindings and views updates are flushed at the end.

and so I expected that when I use it in a test, if the code under test were to schedule some work for later using Ember.run.later that it should complete before the Ember.run call finishes, but that appears not to be so:

test('Ember.run waits for all scheduled actions to finish', function(assert) {
  assert.expect(2);
  var done = assert.async();
  let isRunLaterThingFinished = false;
  Ember.run(function() {
    Ember.run.later(function() {
      isRunLaterThingFinished = true;
      assert.ok(true, 'the scheduled thing happened');
      done();
    }, 1);
  });
  assert.ok(isRunLaterThingFinished, "scheduled actions should have happened by the time ember run finishes");
});

Which results in:

Ember.run waits for all scheduled actions to finish 
1. scheduled actions should have happened by the time ember run finishes
Expected:  true 
Result:    false

Can anyone explain what I'm missing here, and how I can have my tests wait for all of the scheduled methods to finish before doing my asserts?




Aucun commentaire:

Enregistrer un commentaire