@@ -63,58 +63,21 @@ test('fireEvent bubbles event to parent handler', async () => {
6363} ) ;
6464
6565describe ( 'fireEvent.press' , ( ) => {
66- test ( 'works on Pressable' , async ( ) => {
67- const onPress = jest . fn ( ) ;
68- await render ( < Pressable testID = "pressable" onPress = { onPress } /> ) ;
69- await fireEvent . press ( screen . getByTestId ( 'pressable' ) ) ;
70- expect ( onPress ) . toHaveBeenCalled ( ) ;
71- } ) ;
72-
73- test ( 'works on TouchableOpacity' , async ( ) => {
74- const onPress = jest . fn ( ) ;
75- await render (
76- < TouchableOpacity testID = "touchable" onPress = { onPress } >
77- < Text > Press me</ Text >
78- </ TouchableOpacity > ,
79- ) ;
80- await fireEvent . press ( screen . getByTestId ( 'touchable' ) ) ;
81- expect ( onPress ) . toHaveBeenCalled ( ) ;
82- } ) ;
83-
84- test ( 'works on TouchableHighlight' , async ( ) => {
66+ test . each ( [
67+ [ 'Pressable' , Pressable ] ,
68+ [ 'TouchableOpacity' , TouchableOpacity ] ,
69+ [ 'TouchableHighlight' , TouchableHighlight ] ,
70+ [ 'TouchableWithoutFeedback' , TouchableWithoutFeedback ] ,
71+ [ 'TouchableNativeFeedback' , TouchableNativeFeedback ] ,
72+ ] ) ( 'works on %s' , async ( _ , Component ) => {
8573 const onPress = jest . fn ( ) ;
8674 await render (
87- < TouchableHighlight testID = "touchable" onPress = { onPress } >
75+ // @ts -expect-error - Component is a valid React component
76+ < Component testID = "subject" onPress = { onPress } >
8877 < Text > Press me</ Text >
89- </ TouchableHighlight > ,
78+ </ Component > ,
9079 ) ;
91- await fireEvent . press ( screen . getByTestId ( 'touchable' ) ) ;
92- expect ( onPress ) . toHaveBeenCalled ( ) ;
93- } ) ;
94-
95- test ( 'works on TouchableWithoutFeedback' , async ( ) => {
96- const onPress = jest . fn ( ) ;
97- await render (
98- < TouchableWithoutFeedback testID = "touchable" onPress = { onPress } >
99- < View >
100- < Text > Press me</ Text >
101- </ View >
102- </ TouchableWithoutFeedback > ,
103- ) ;
104- await fireEvent . press ( screen . getByTestId ( 'touchable' ) ) ;
105- expect ( onPress ) . toHaveBeenCalled ( ) ;
106- } ) ;
107-
108- test ( 'works on TouchableNativeFeedback' , async ( ) => {
109- const onPress = jest . fn ( ) ;
110- await render (
111- < TouchableNativeFeedback testID = "touchable" onPress = { onPress } >
112- < View >
113- < Text > Press me</ Text >
114- </ View >
115- </ TouchableNativeFeedback > ,
116- ) ;
117- await fireEvent . press ( screen . getByTestId ( 'touchable' ) ) ;
80+ await fireEvent . press ( screen . getByTestId ( 'subject' ) ) ;
11881 expect ( onPress ) . toHaveBeenCalled ( ) ;
11982 } ) ;
12083} ) ;
@@ -129,14 +92,6 @@ describe('fireEvent.changeText', () => {
12992 expect ( nativeState . valueForElement . get ( input ) ) . toBe ( 'new text' ) ;
13093 } ) ;
13194
132- test ( 'updates native state for uncontrolled TextInput' , async ( ) => {
133- await render ( < TextInput testID = "input" /> ) ;
134- const input = screen . getByTestId ( 'input' ) ;
135- await fireEvent . changeText ( input , 'hello' ) ;
136- expect ( input ) . toHaveDisplayValue ( 'hello' ) ;
137- expect ( nativeState . valueForElement . get ( input ) ) . toBe ( 'hello' ) ;
138- } ) ;
139-
14095 test ( 'does not fire on non-editable TextInput' , async ( ) => {
14196 const onChangeText = jest . fn ( ) ;
14297 await render ( < TextInput testID = "input" editable = { false } onChangeText = { onChangeText } /> ) ;
0 commit comments