如何在测试Ember.js组件时触发focus和blur事件?this.$().focus();或this.$('input').focus();看起来可以正常工作,但在幻像js和chrome中表现不同。此外,this.$().blur();或this.$().focusout();似乎不工作的phantomjs和铬。
this.$().focus();
this.$('input').focus();
this.$().blur();
this.$().focusout();
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
zbsbpyhn2#
用trigger试一试,它对我很有效
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
2条答案
按热度按时间ct3nt3jp1#
新版本的Ember有测试助手,可以用来聚焦或模糊。
模糊:https://github.com/emberjs/ember-test-helpers/blob/master/API.md#blur
焦点:https://github.com/emberjs/ember-test-helpers/blob/master/API.md#focus
zbsbpyhn2#
用
trigger
试一试,它对我很有效more information