File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change 11import { ReactTestInstance } from 'react-test-renderer' ;
2+ import {
3+ ViewProps ,
4+ TextProps ,
5+ TextInputProps ,
6+ PressableProps ,
7+ ScrollViewProps ,
8+ } from 'react-native' ;
29import act from './act' ;
310import { isHostElement } from './helpers/component-tree' ;
411import { getHostComponentNames } from './helpers/host-component-names' ;
@@ -108,9 +115,27 @@ function getEventHandlerName(eventName: string) {
108115 return `on${ eventName . charAt ( 0 ) . toUpperCase ( ) } ${ eventName . slice ( 1 ) } ` ;
109116}
110117
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+
111136function fireEvent (
112137 element : ReactTestInstance ,
113- eventName : string ,
138+ eventName : EventName ,
114139 ...data : unknown [ ]
115140) {
116141 const handler = findEventHandler ( element , eventName ) ;
You can’t perform that action at this time.
0 commit comments