File tree 1 file changed +26
-1
lines changed
1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { ReactTestInstance } from 'react-test-renderer' ;
2
+ import {
3
+ ViewProps ,
4
+ TextProps ,
5
+ TextInputProps ,
6
+ PressableProps ,
7
+ ScrollViewProps ,
8
+ } from 'react-native' ;
2
9
import act from './act' ;
3
10
import { isHostElement } from './helpers/component-tree' ;
4
11
import { getHostComponentNames } from './helpers/host-component-names' ;
@@ -108,9 +115,27 @@ function getEventHandlerName(eventName: string) {
108
115
return `on${ eventName . charAt ( 0 ) . toUpperCase ( ) } ${ eventName . slice ( 1 ) } ` ;
109
116
}
110
117
118
+ // Allows any string but will provide autocomplete for type T
119
+ type StringWithAutoComplete < T > = T | ( string & Record < never , never > ) ;
120
+
121
+ // String union type of keys of T that start with on, stripped from on
122
+ type OnKeys < T > = keyof {
123
+ [ K in keyof T as K extends `on${infer Rest } `
124
+ ? Uncapitalize < Rest >
125
+ : never ] : T [ K ] ;
126
+ } ;
127
+
128
+ type EventName = StringWithAutoComplete <
129
+ | OnKeys < ViewProps >
130
+ | OnKeys < TextProps >
131
+ | OnKeys < TextInputProps >
132
+ | OnKeys < PressableProps >
133
+ | OnKeys < ScrollViewProps >
134
+ > ;
135
+
111
136
function fireEvent (
112
137
element : ReactTestInstance ,
113
- eventName : string ,
138
+ eventName : EventName ,
114
139
...data : unknown [ ]
115
140
) {
116
141
const handler = findEventHandler ( element , eventName ) ;
You can’t perform that action at this time.
0 commit comments