Skip to content

Commit e49ef3c

Browse files
committed
fix: fireEvent assumptions about RN tree structure
1 parent fe0b189 commit e49ef3c

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

src/__tests__/fire-event.test.tsx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ const OnPressComponent = ({ onPress, text }: OnPressComponentProps) => (
2323
</View>
2424
);
2525

26-
type WithoutEventComponentProps = { onPress: () => void };
27-
const WithoutEventComponent = (_props: WithoutEventComponentProps) => (
28-
<View>
29-
<Text>Without event</Text>
30-
</View>
31-
);
32-
3326
type CustomEventComponentProps = {
3427
onCustomEvent: () => void;
3528
};
@@ -75,16 +68,6 @@ describe('fireEvent', () => {
7568
expect(onPressMock).toHaveBeenCalled();
7669
});
7770

78-
test('should not fire if the press handler is not passed to children', () => {
79-
const onPressMock = jest.fn();
80-
render(
81-
// TODO: this functionality is buggy, i.e. it will fail if we wrap this component with a View.
82-
<WithoutEventComponent onPress={onPressMock} />,
83-
);
84-
fireEvent(screen.getByText('Without event'), 'press');
85-
expect(onPressMock).not.toHaveBeenCalled();
86-
});
87-
8871
test('should invoke event with custom name', () => {
8972
const handlerMock = jest.fn();
9073
const EVENT_DATA = 'event data';

src/fire-event.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ function findEventHandler(
8282
const touchResponder = isTouchResponder(element) ? element : nearestTouchResponder;
8383

8484
const handler = getEventHandler(element, eventName, { loose: true });
85-
if (handler && isEventEnabled(element, eventName, touchResponder)) return handler;
85+
if (handler && isEventEnabled(element, eventName, touchResponder)) {
86+
return handler;
87+
}
8688

87-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
88-
if (element.parent === null || element.parent.parent === null) {
89+
if (element.parent === null) {
8990
return null;
9091
}
9192

0 commit comments

Comments
 (0)