6
6
createLibraryNotSupportedError ,
7
7
prepareErrorMessage ,
8
8
throwRemovedFunctionError ,
9
+ throwRenamedFunctionError ,
9
10
} from './errors' ;
10
11
11
12
const filterNodeByType = ( node , type ) => node . type === type ;
@@ -50,7 +51,7 @@ const getChildrenAsText = (children, TextComponent, textContent = []) => {
50
51
return textContent ;
51
52
} ;
52
53
53
- const getTextInputNodeByPlaceholder = ( node , placeholder ) => {
54
+ const getTextInputNodeByPlaceholderText = ( node , placeholder ) => {
54
55
try {
55
56
// eslint-disable-next-line
56
57
const { TextInput } = require ( 'react-native' ) ;
@@ -89,14 +90,17 @@ export const getByText = (instance: ReactTestInstance) =>
89
90
}
90
91
} ;
91
92
92
- export const getByPlaceholder = ( instance : ReactTestInstance ) =>
93
- function getByPlaceholderFn ( placeholder : string | RegExp ) {
93
+ export const getByPlaceholderText = ( instance : ReactTestInstance ) =>
94
+ function getByPlaceholderTextFn ( placeholder : string | RegExp ) {
94
95
try {
95
96
return instance . find ( ( node ) =>
96
- getTextInputNodeByPlaceholder ( node , placeholder )
97
+ getTextInputNodeByPlaceholderText ( node , placeholder )
97
98
) ;
98
99
} catch ( error ) {
99
- throw new ErrorWithStack ( prepareErrorMessage ( error ) , getByPlaceholderFn ) ;
100
+ throw new ErrorWithStack (
101
+ prepareErrorMessage ( error ) ,
102
+ getByPlaceholderTextFn
103
+ ) ;
100
104
}
101
105
} ;
102
106
@@ -142,15 +146,15 @@ export const getAllByText = (instance: ReactTestInstance) =>
142
146
return results ;
143
147
} ;
144
148
145
- export const getAllByPlaceholder = ( instance : ReactTestInstance ) =>
146
- function getAllByPlaceholderFn ( placeholder : string | RegExp ) {
149
+ export const getAllByPlaceholderText = ( instance : ReactTestInstance ) =>
150
+ function getAllByPlaceholderTextFn ( placeholder : string | RegExp ) {
147
151
const results = instance . findAll ( ( node ) =>
148
- getTextInputNodeByPlaceholder ( node , placeholder )
152
+ getTextInputNodeByPlaceholderText ( node , placeholder )
149
153
) ;
150
154
if ( results . length === 0 ) {
151
155
throw new ErrorWithStack (
152
156
`No instances found with placeholder: ${ String ( placeholder ) } ` ,
153
- getAllByPlaceholderFn
157
+ getAllByPlaceholderTextFn
154
158
) ;
155
159
}
156
160
return results ;
@@ -226,11 +230,11 @@ export const UNSAFE_getAllByProps = (instance: ReactTestInstance) =>
226
230
227
231
export const getByAPI = ( instance : ReactTestInstance ) => ( {
228
232
getByText : getByText ( instance ) ,
229
- getByPlaceholder : getByPlaceholder ( instance ) ,
233
+ getByPlaceholderText : getByPlaceholderText ( instance ) ,
230
234
getByDisplayValue : getByDisplayValue ( instance ) ,
231
235
getByTestId : getByTestId ( instance ) ,
232
236
getAllByText : getAllByText ( instance ) ,
233
- getAllByPlaceholder : getAllByPlaceholder ( instance ) ,
237
+ getAllByPlaceholderText : getAllByPlaceholderText ( instance ) ,
234
238
getAllByDisplayValue : getAllByDisplayValue ( instance ) ,
235
239
getAllByTestId : getAllByTestId ( instance ) ,
236
240
@@ -256,4 +260,10 @@ export const getByAPI = (instance: ReactTestInstance) => ({
256
260
'getAllByProps' ,
257
261
'migration-v2#removed-functions'
258
262
) ,
263
+
264
+ // Renamed
265
+ getByPlaceholder : ( ) =>
266
+ throwRenamedFunctionError ( 'getByPlaceholder' , 'getByPlaceholderText' ) ,
267
+ getAllByPlaceholder : ( ) =>
268
+ throwRenamedFunctionError ( 'getAllByPlaceholder' , 'getByPlaceholderText' ) ,
259
269
} ) ;
0 commit comments