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

esbemjvw  于 2022-11-23  发布在  其他
关注(0)|答案(2)|浏览(175)

如何在测试Ember.js组件时触发focus和blur事件?
this.$().focus();this.$('input').focus();看起来可以正常工作,但在幻像js和chrome中表现不同。
此外,this.$().blur();this.$().focusout();似乎不工作的phantomjs和铬。

ct3nt3jp

ct3nt3jp1#

新版本的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

zbsbpyhn

zbsbpyhn2#

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

相关问题