【问题标题】:Ember Test: input focusEmber 测试:输入焦点
【发布时间】:2017-03-18 12:57:58
【问题描述】:

我真的不明白这里发生的一系列事件。尽可能地关注guide。我有:

test('Tab focus', function(assert) { 
    visit('/demo/form');
    click('input[type=text]');
    andThen(function() {
        assert.equal(
            find('input[type=text]').css('borderTopColor'), 'rgb(0, 125, 164)', 'Text input has focus'
        );
    });
});

只是让它失败:

颜色变化没有过渡,如果我点击重新运行,它确实通过了。

【问题讨论】:

  • 如果您使用 find('input[type=text]').is(":focus") 测试焦点会发生什么?
  • find('input[type=text]').is(':focus')find('input[type=text]:focus') 都不会按预期返回 true/.length = 1。 :(
  • 如果你能用例子搭建一个ember twiddle (ember-twiddle.com),也许我们几个可以看看?

标签: unit-testing ember.js ember-qunit ember-testing


【解决方案1】:

对于仍在寻找答案的任何人 - 您必须在测试中手动触发“焦点”事件:

triggerEvent(<alement selector>, 'focus');

更多信息:https://guides.emberjs.com/v2.14.0/testing/acceptance/#toc_asynchronous-helpers

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-13
    • 1970-01-01
    • 2017-12-17
    • 2010-11-01
    相关资源
    最近更新 更多