( props: Record<string, unknown>, eventName: string, options?: EventHandlerOptions, )
| 6 | }; |
| 7 | |
| 8 | export function getEventHandlerFromProps( |
| 9 | props: Record<string, unknown>, |
| 10 | eventName: string, |
| 11 | options?: EventHandlerOptions, |
| 12 | ): EventHandler | undefined { |
| 13 | const handlerName = getEventHandlerName(eventName); |
| 14 | if (typeof props[handlerName] === 'function') { |
| 15 | return props[handlerName] as EventHandler; |
| 16 | } |
| 17 | |
| 18 | if (options?.loose && typeof props[eventName] === 'function') { |
| 19 | return props[eventName] as EventHandler; |
| 20 | } |
| 21 | |
| 22 | if (typeof props[`testOnly_${handlerName}`] === 'function') { |
| 23 | return props[`testOnly_${handlerName}`] as EventHandler; |
| 24 | } |
| 25 | |
| 26 | if (options?.loose && typeof props[`testOnly_${eventName}`] === 'function') { |
| 27 | return props[`testOnly_${eventName}`] as EventHandler; |
| 28 | } |
| 29 | |
| 30 | return undefined; |
| 31 | } |
| 32 | |
| 33 | function getEventHandlerName(eventName: string) { |
| 34 | return `on${capitalizeFirstLetter(eventName)}`; |
no test coverage detected
searching dependent graphs…