从验收测试中触发输入的操作? [英] Trigger an input's action from an acceptance test?

查看:104
本文介绍了从验收测试中触发输入的操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的模板中找到了:

  {{input 
value = model.title
focus-out =finishEditingTitle
insert-newline =finishEditingTitle
}}

该操作是异步的。我想测试一下,用户完成编辑文本字段后,会执行操作,结果反映在页面上。



我尝试过这个

  fillIn('input','asdf'); 
keyEvent('input','keypress',13);

但它不会触发动作!



同时,在< button {{actionsave}}>之后,执行单击('button'); 确实会触发该操作。



如何从验收测试中触发输入的操作?



一个小提琴: http:/ //////想要等待,以便在进行测试之前完成UI事件。



您需要继续使用承诺。如果您的需求更加复杂,则您必须在控制器中编写自定义代码,以确保发生这种情况。 (例如:使用Ember(cli)如何获得验收测试等待承诺?)。



幸运的是,您的情况已经有帮助者照顾不同步,请参阅: http://emberjs.com/guides/testing/test-helpers/



实际答案只是: p>

  click('。title'); 
fillIn('input','asdf');
triggerEvent('input','blur');

请注意,这不起作用:

  // triggerEvent('input','blur'); 
Ember。$('< input>')。blur();


I've got this in my template:

  {{ input
    value=model.title
    focus-out="finishEditingTitle"
    insert-newline="finishEditingTitle"
  }}

The action is asynchronous. I would like to test that after a user finishes editing the text field, the action is performed and the result is reflected on the page.

I tried this

fillIn('input', 'asdf');
keyEvent('input', 'keypress', 13);

But it won't trigger the action!

At the same time, doing click('button'); on a <button {{action "save"}}> does trigger the action.

How do i trigger an input's action from an acceptance test?

A fiddle: http://emberjs.jsbin.com/dapuge/1/edit?html,js,output

解决方案

So, you want to wait for the UI events to complete before doing your tests.

You need to keep working with promises. If your needs were more convoluted, you would have to write custom code in your controller to make sure this happens. (For example: Using Ember (cli) how do I get an acceptance test to wait for a promise?).

Luckily for your case there are already helpers that take care of the asynchrony, see: http://emberjs.com/guides/testing/test-helpers/

The actual answer, just:

click('.title');
fillIn('input', 'asdf');
triggerEvent('input', 'blur');

Note, this wouldn't work:

//triggerEvent('input', 'blur');
Ember.$('<input>').blur();

这篇关于从验收测试中触发输入的操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆