使用酶模拟自定义事件? [英] Using Enzyme simulate on custom events?

查看:70
本文介绍了使用酶模拟自定义事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在自定义事件中使用酶的.simulate()方法。
例如:

It is possible to use Enzyme's method .simulate() on custom events. For Example:

// Code
<Element onFoo={someFunction}></Elements>

// Test
const element = shallow(<Element>);
element.simulate('foo');

这是应该使用Enzyme测试自定义事件的方式,还是使用s的更好方法? th。像这样:

Is this the way custom events should be tested with Enzyme or is it a better approach to use s.th. like:

//Test
const element = shallow(<Element>);
element.props.onFoo()


推荐答案

自定义事件的 .simulate()似乎未实现。 github上有一个问题,其中讨论了该主题,也是之一酶维护人员建议使用您提供的第二种方法:

It seems that .simulate() for custom events is not implemented. There is an issue on github, where this topic is discussed and one of the Enzyme maintainers suggests to use the second approach you've provided:

wrapper.find(Child).prop('customEvent')(fakeEvent)

这篇关于使用酶模拟自定义事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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