在连续Ember.run.later期间单击验收测试

时间:2017-03-24 13:19:53

标签: asynchronous ember.js automated-tests acceptance-testing

在控制器中我有Ember.run.later循环,它会不断更新计时器。

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

在验收测试中,我想点击按钮,这应暂停此循环:

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);
  });
});

但在点击之前测试暂停并等待循环停止。

如何在循环期间触发此点击并停止继续测试?

以下是展示此问题的小谜语: https://ember-twiddle.com/a72ca75527ec4cdc0c3d1c9ebcb421e0?openFiles=tests.acceptance.my-acceptance-test.js%2C

1 个答案:

答案 0 :(得分:1)

我刚刚发现,我可以通过不使用测试助手来实现这一点:

echo()

但我不确定这是处理此问题的正确方法。