如何在ember集成测试中对组件进行聚焦/模糊?

yka*_*gol 7 jquery phantomjs ember.js ember-testing ember-components

如何在测试Ember.js组件时触发焦点和模糊事件?

this.$().focus();this.$('input').focus();似乎工作但在phantomjs和chrome中表现不同.

this.$().blur();this.$().focusout();似乎没有工作phantomjs和铬.

ajp*_*nam 1

新版本的 Ember 有测试助手,可用于聚焦或模糊。

... 
import { find, focus, blur, render } from '@ember/test-helpers';


module('Integration | Component | example-input', function(hooks) {
  
  test('it can be focused', async function(assert) {
    await render(hbs`<myInput />`);
    const input = find('input')
    
    await focus(input)
    await blur(input)
  });
  
});
Run Code Online (Sandbox Code Playgroud)

模糊:https://github.com/emberjs/ember-test-helpers/blob/master/API.md#blur

焦点:https ://github.com/emberjs/ember-test-helpers/blob/master/API.md#focus