我正在使用enzyme + jest来测试react App,是否可以在可编辑的span元素上触发onKeyDown事件?
<span id = 'name' contenteditable = 'true'> Editable text </span>
我尝试过:
result.find('#name').simulate('keyDown', { key: 'm', keyCode: 77, which: 77 });,
但是没有成功。元素内容保持不变。
最佳答案
这不是 enzyme 的工作原理。它只能模拟在React Explicit中添加的事件。来自文档
Even though the name would imply this simulates an actual event, .simulate() will in fact target the component's prop based on the event you give it. For example, .simulate('click') will actually get the onClick prop and call it.
关于reactjs - 在 Contenteditable 元素上触发事件 keyDown(测试 + react + Jest + enzyme ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43763398/