MCPcopy
hub / github.com/callstack/react-native-testing-library / getEventHandlerFromProps

Function getEventHandlerFromProps

src/event-handler.ts:8–31  ·  view source on GitHub ↗
(
  props: Record<string, unknown>,
  eventName: string,
  options?: EventHandlerOptions,
)

Source from the content-addressed store, hash-verified

6};
7
8export 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
33function getEventHandlerName(eventName: string) {
34 return `on${capitalizeFirstLetter(eventName)}`;

Callers 5

findEventHandlerFunction · 0.90
dispatchEventFunction · 0.90
hasPressEventHandlerFunction · 0.90

Calls 1

getEventHandlerNameFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…