Skip to content

Commit 53e2925

Browse files
Pontus Lundinthymikee
Pontus Lundin
authored andcommitted
do not throw when event handler was not found
1 parent 62ccd08 commit 53e2925

File tree

2 files changed

+1
-19
lines changed

2 files changed

+1
-19
lines changed

src/__tests__/fireEvent.test.js

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

65-
test('should throw an Error when event handler was not found', () => {
66-
const { getByText } = render(
67-
<WithoutEventComponent onPress={() => 'this is not passed to children'} />
68-
);
69-
70-
expect(() => fireEvent(getByText('Without event'), 'press')).toThrow(
71-
'No handler function found for event: "press"'
72-
);
73-
});
74-
7565
test('should invoke event with custom name', () => {
7666
const handlerMock = jest.fn();
7767
const EVENT_DATA = 'event data';

src/fireEvent.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @flow
22
import act from './act';
3-
import { ErrorWithStack } from './helpers/errors';
43

54
const isHostElement = (element?: ReactTestInstance) => {
65
return typeof element?.type === 'string';
@@ -66,14 +65,7 @@ const findEventHandler = (
6665
// Do not bubble event to the root element
6766
const hasHandler = handler != null || hasDescendandHandler;
6867
if (element.parent === null || element.parent.parent === null) {
69-
if (hasHandler) {
70-
return null;
71-
} else {
72-
throw new ErrorWithStack(
73-
`No handler function found for event: "${eventName}"`,
74-
callsite || invokeEvent
75-
);
76-
}
68+
return null;
7769
}
7870

7971
return findEventHandler(

0 commit comments

Comments
 (0)