关键preSS事件AngularJS单元测试 [英] AngularJS unit test for keypress event

查看:125
本文介绍了关键preSS事件AngularJS单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置结合了KeyDown和关键为preSS事件功能的指令。输入一个快捷键时,指令设置焦点窗体上的输入。

I set up a directive that binds a function for the keydown and keypress events. The directive sets the focus for an input on a form when a shortcut key is entered.

<input type="text" id=txtField1" focus-key="a" />
<input type="text" id=txtField2" focus-key="b" />
<input type="text" id=txtField3" focus-key="c" />

是否有可能触发单元测试我的指令的关键preSS事件?在此先感谢您的帮助。

Is it possible to trigger the keypress event for unit testing my directives? Thanks in advance for your help.

推荐答案

您可以使用jQuery与AngularJS,你可以在jQuery的做到这一点很容易用的触发器() API呼叫。可以传递一个事件到触发器,在这种情况下,事件是

You can use jQuery with AngularJS, and you can do this fairly easily in jQuery with the trigger() API call. You can pass an event into trigger, in this case the event is the

var aEvent = jQuery.Event("keydown");
aEvent.which = 40; //this is the ASCII value of the key you want to press
$("input").trigger(aEvent);

然后重复为其他字符。

Then repeat for the other characters.

这篇关于关键preSS事件AngularJS单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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