Skip to content

Commit 44a9d27

Browse files
committed
refactor: code review changes
1 parent 6abfbd0 commit 44a9d27

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

src/fireEvent.js

+8-19
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,15 @@ const findEventHandler = (
99
nearestHostDescendent?: ReactTestInstance
1010
) => {
1111
const isHostComponent = typeof element.type === 'string';
12-
const nearestHostComponent = isHostComponent
13-
? element
14-
: nearestHostDescendent;
12+
const hostElement = isHostComponent ? element : nearestHostDescendent;
13+
const isEventEnabled =
14+
hostElement?.props.onStartShouldSetResponder?.() !== false;
1515

16-
const eventHandler = toEventHandlerName(eventName);
16+
const eventHandlerName = toEventHandlerName(eventName);
1717

18-
if (
19-
typeof element.props[eventHandler] === 'function' &&
20-
nearestHostComponent?.props.onStartShouldSetResponder?.() !== false
21-
) {
22-
return element.props[eventHandler];
23-
} else if (
24-
typeof element.props[eventName] === 'function' &&
25-
nearestHostComponent?.props.onStartShouldSetResponder?.() !== false
26-
) {
18+
if (typeof element.props[eventHandlerName] === 'function' && isEventEnabled) {
19+
return element.props[eventHandlerName];
20+
} else if (typeof element.props[eventName] === 'function' && isEventEnabled) {
2721
return element.props[eventName];
2822
}
2923

@@ -35,12 +29,7 @@ const findEventHandler = (
3529
);
3630
}
3731

38-
return findEventHandler(
39-
element.parent,
40-
eventName,
41-
callsite,
42-
nearestHostComponent
43-
);
32+
return findEventHandler(element.parent, eventName, callsite, hostElement);
4433
};
4534

4635
const invokeEvent = (

0 commit comments

Comments
 (0)