Skip to content

Commit 38f93ee

Browse files
committed
remove unnecessary hasDescendandHandler
1 parent 53e2925 commit 38f93ee

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/__tests__/fireEvent.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ describe('fireEvent', () => {
6262
expect(onPressMock).toHaveBeenCalled();
6363
});
6464

65+
test('should not fire if the press handler is not passed to children', () => {
66+
const onPressMock = jest.fn();
67+
const { getByText } = render(
68+
// TODO: this functionality is buggy, i.e. it will fail if we wrap this component with a View.
69+
<WithoutEventComponent onPress={onPressMock} />
70+
);
71+
fireEvent(getByText('Without event'), 'press');
72+
expect(onPressMock).not.toHaveBeenCalled();
73+
});
74+
6575
test('should invoke event with custom name', () => {
6676
const handlerMock = jest.fn();
6777
const EVENT_DATA = 'event data';

src/fireEvent.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ const findEventHandler = (
5252
element: ReactTestInstance,
5353
eventName: string,
5454
callsite?: any,
55-
nearestTouchResponder?: ReactTestInstance,
56-
hasDescendandHandler?: boolean
55+
nearestTouchResponder?: ReactTestInstance
5756
) => {
5857
const touchResponder = isTouchResponder(element)
5958
? element
@@ -62,19 +61,11 @@ const findEventHandler = (
6261
const handler = getEventHandler(element, eventName);
6362
if (handler && isEventEnabled(element, touchResponder)) return handler;
6463

65-
// Do not bubble event to the root element
66-
const hasHandler = handler != null || hasDescendandHandler;
6764
if (element.parent === null || element.parent.parent === null) {
6865
return null;
6966
}
7067

71-
return findEventHandler(
72-
element.parent,
73-
eventName,
74-
callsite,
75-
touchResponder,
76-
hasHandler
77-
);
68+
return findEventHandler(element.parent, eventName, callsite, touchResponder);
7869
};
7970

8071
const getEventHandler = (element: ReactTestInstance, eventName: string) => {

0 commit comments

Comments
 (0)