首页 > 解决方案 > 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();

请提出两个事件之间的区别。

标签: javascriptangularjasmine

解决方案


推荐阅读