【问题标题】:How do you generate a blur or onBlur event in Enzyme?如何在 Enzyme 中生成 blur 或 onBlur 事件?
【发布时间】:2016-12-22 01:48:21
【问题描述】:

我试过了:

input.simulate('blur');

input.simulate('onBlur');

这些都不起作用。这在 Enzyme 中是否可用(我使用的是 2.4.1 版)。

【问题讨论】:

  • 我以前用过simulate('blur');,效果很好。

标签: unit-testing reactjs frontend enzyme


【解决方案1】:

input.simulate('focus')input.simulate('change')input.simulate('blur') 应该可以工作。检查您的 input 是否实际上是声明为 _wrapper.find('input') 的节点并且存在。其次,还有一个类似的问题:Enzyme - How to access and set <input> value? 最后,如果你是check the source codeReactWrapper component,那么你会发现它使用了all events that React can recognize。所以错误就在你的代码中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-02
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 2016-04-27
    • 2022-10-30
    相关资源
    最近更新 更多