javascript - Angular 单元测试用例键盘事件不起作用
问题描述
我有一个单元测试用例,用于文本区域上的键盘输入键事件,但它不起作用。
代码.spec.ts
textArea.value = "abcd`~";
const event = new KeyboardEvent("keypress",{
"key": "Enter"
});
textArea.dispatchEvent(event);
但我尝试了另一种方式来触发文本区域事件,但它的工作,
textArea.dispatchEvent(new Event('input')); // I can trigger the event
fixture.detectChanges();
请提出两个事件之间的区别。
解决方案
推荐阅读
- php - 无法读取 PHP YII1.1 中 6 个位置的 cron 表达式
- python - 例外:版本不匹配:这是 'cffi' 软件包版本 1.13.1,
- html - 如何让下拉菜单出现在div前面?
- java - 是否有关于 TransactionalEventListener 总是接收事件
- javascript - 确保不存在重复的目录路径
- sql - 可以为连接表设置限制吗?
- hash - uboot 2009(iMX25 处理器)上的慢速哈希(sha256)
- python-hypothesis - 如何使用 python 假设创建复杂的数据结构
- mongodb - 打开 Robo 3T 时缺少 api-ms-win-crt-runtime-l1-1-0.dll
- ios - 如何查看“音乐应用”是如何安装的?