Enzyme 的模拟接受什么样的事件?
What kind of events are accepted by Enzyme's simulate?
我知道 simulate('click')
用于测试点击某个组件,但为什么不是 simulate('onClick')
?为什么需要 'change' 而不是 'onChange'?
'click' 和 'change' 不是原生 html 事件。文档说它只需要一个 ol' 字符串。
/**
* Simulate events.
* Returns itself.
* @param args?
*/
simulate(event: string, ...args: any[]): this;
是否有类型列表作为事件参数接受的字符串类型的真实来源?
.simulate()
will call .simulateEvent()
method, and .simulateEvent()
will call propFromEvent()
function and it will call mapNativeEventNames()
将浏览器本机事件名称映射到没有前缀 on
的反应事件驼峰命名。例如。 'touchstart'
将映射到 'touchStart'
.
然后,propFromEvent()
会将原生事件名称映射到带有前缀 on
的 React 元素道具事件驼峰命名。例如。 'click' => 'onClick'
、'mouseEnter' => 'onMouseEnter'
因此,.simulate(event)
接受浏览器原生 event type same with addEventListener。它将帮助您映射到 React 事件道具。
事件类型的完整列表:w3c
我知道 simulate('click')
用于测试点击某个组件,但为什么不是 simulate('onClick')
?为什么需要 'change' 而不是 'onChange'?
'click' 和 'change' 不是原生 html 事件。文档说它只需要一个 ol' 字符串。
/**
* Simulate events.
* Returns itself.
* @param args?
*/
simulate(event: string, ...args: any[]): this;
是否有类型列表作为事件参数接受的字符串类型的真实来源?
.simulate()
will call .simulateEvent()
method, and .simulateEvent()
will call propFromEvent()
function and it will call mapNativeEventNames()
将浏览器本机事件名称映射到没有前缀 on
的反应事件驼峰命名。例如。 'touchstart'
将映射到 'touchStart'
.
然后,propFromEvent()
会将原生事件名称映射到带有前缀 on
的 React 元素道具事件驼峰命名。例如。 'click' => 'onClick'
、'mouseEnter' => 'onMouseEnter'
因此,.simulate(event)
接受浏览器原生 event type same with addEventListener。它将帮助您映射到 React 事件道具。
事件类型的完整列表:w3c