在验收测试中,在文本输入后按Enter键会触发事件。我尝试填充文本并使用keyEvent按Enter键。
PS:Testem忽略了keyEvent。
HTML:
<div class="issue-container">
<div class="create-container">
<div class="input-field ui-textarea md-animated ember-view">
<label id="ember1369-label" for="ember1369-input" class="active">Add an issue</label>
<textarea data-test-id="txtid" id="ember1369-input" class="md-textarea" style="height: 21.5px; overflow: hidden;"></textarea></div></div></div>
验收测试:
test('review-an-element', async function(assert) {
await fillIn(testSelector('txtid'), 'Input is typed here and then hit enter');
await keyEvent(testSelector('txtid'), 'keypress', 13);}); //hitting enter
我的jQuery尝试:
var e = jQuery.Event("keyup");
e.which = 13;
e.keyCode = 13;
await $('.md-textarea').trigger(e);
答案 0 :(得分:1)
您需要处理keyup
事件,而不是keypress
事件。 keypress
事件仅触发生成输出的键,如字母键。参考:https://developer.mozilla.org/en-US/docs/Web/Events/keypress
进行验收测试:
更改
await keyEvent(testSelector('txtid'), 'keypress', 13);
到
await keyEvent(testSelector('txtid'), 'keyup', 13);
修改:testSelector()
帮助程序已弃用 - https://github.com/simplabs/ember-test-selectors/pull/134
答案 1 :(得分:0)
我的jQuery解决方案。
var e = $.Event('keydown', { keyCode: 13 });
test('txtarea', async function(assert){
await fillIn($('.md-textarea')[0], 'text is entered here');
await $('.md-textarea').trigger(e);
});