vendredi 24 mars 2017

Click in acceptance test during continuous Ember.run.later

In the controller I have Ember.run.later loop, which continuously updates the timer.

run: function() {
    const lastResumeTimestamp = this.get("lastResumeTimestamp");
    this.clearTimer();
    this.set('timerId', Ember.run.later(this, function() {
    // update the timer  
    // ...
      this.run();
    }, 100));
  },

In acceptance test I want to click button, which should pause this loop:

test('I want to start/pause new activity', function(assert) {
  visit('/');
  andThen(function() {
    assert.equal(find('.duration', activityBuilderSelector).text(), "0");

    click('.start-activity-button', activityBuilderSelector);
    // -->> start continuous Ember.run.later.loop, see: application cortroller

    waitFor(assert, function() {
      const val = find('.duration', activityBuilderSelector).text()
      assert.notEqual(val, "0", `notEqual 0 (${val})`);
      assert.equal(find('.title', activityBuilderSelector).text(), "New activity", "there should be activity title");
      // -->> here test waiting because of run.later loop
      click('.pause-activity-button', activityBuilderSelector);
    });
  });

  andThen(function() {
      //click('.resume-activity-button', activityBuilderSelector);
  });
});

but test pause before the click and waiting for loop stop.

How can I trigger this click during loop and stop it to continue test?

Here is little twiddle which demonstrate this issue: http://ift.tt/2mz2J7S




Aucun commentaire:

Enregistrer un commentaire