UNPKG

component-test-utils-react

Version:

Test react component the same way as other frameworks

22 lines (18 loc) 505 B
const {getHtml} = require('./html'); exports.dispatchEvent = (reactTree, eventName) => { const eventNameCaseOk = `${eventName .charAt(0) .toUpperCase()}${eventName.slice(1)}`; if (!reactTree.props[`on${eventNameCaseOk}`]) { throw new Error( `Cannot dispatch event "${eventName}" on this node : ${getHtml({ ...reactTree, props: { ...reactTree.props, children: null } })}` ); } reactTree.props[`on${eventNameCaseOk}`](); };