如何在 ember 集成测试中对组件进行 focus/blur?

How to focus/blur on a component in ember integration tests?

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

this.$().focus();this.$('input').focus(); 似乎有效,但在 phantomjs 和 chrome.

中表现不同

此外 this.$().blur();this.$().focusout(); 似乎无法同时使用 phantomjs 和 chrome。

trigger 试一试,它对我有用

  this.$('input').focusout();
  this.$('input').blur();
  this.$('input').trigger('focusout');
  this.$('input').trigger('blur');
  this.$('input').trigger('keyup'); // another event that you can trigger

more information

较新版本的 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)
  });
  
});

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

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