【问题标题】:How is helper 'andThen' in ember is different than traditional 'then'ember 中的 helper 'andThen' 与传统的 'then' 有何不同
【发布时间】:2023-03-24 10:14:02
【问题描述】:

在下面的代码中,我可以使用then 而不是andThen,我看到一切运行良好。那么,是什么让 andThen 如此特别?

test('Clicked on the About page /about', function(assert) {
    visit('/')
    .click('a:contains("About")')
    .then(function(){
        assert.equal(currentURL(), '/about', 'SHould Navigate to about')
    })
});

test('Clicked on the About page /about', function(assert) {
    visit('/')
    .click('a:contains("About")')
    .andThen(function(){
        assert.equal(currentURL(), '/about', 'SHould Navigate to about')
    })
});

【问题讨论】:

    标签: javascript ember.js promise


    【解决方案1】:

    then 与等待完成加载的承诺有关。 andThen 在调用内部代码之前等待 Ember 的 runloop 完成。

    此外,在 Ember 中较新样式的测试中,测试助手(点击、填充等)都返回承诺,我们不再需要使用 andThen

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-18
      • 1970-01-01
      相关资源
      最近更新 更多