File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -173,13 +173,26 @@ export const getAllByProps = (instance: ReactTestInstance) =>
173
173
return results ;
174
174
} ;
175
175
176
+ export const getAllByTestId = ( instance : ReactTestInstance ) =>
177
+ function getAllByTestIdFn ( testID : string ) {
178
+ const results = instance . findAllByProps ( { testID } ) ;
179
+ if ( results . length === 0 ) {
180
+ throw new ErrorWithStack (
181
+ `No instances found with testID: ${ String ( testID ) } ` ,
182
+ getAllByTestIdFn
183
+ ) ;
184
+ }
185
+ return results ;
186
+ } ;
187
+
176
188
export const getByAPI = ( instance : ReactTestInstance ) => ( {
177
189
getByTestId : getByTestId ( instance ) ,
178
190
getByName : getByName ( instance ) ,
179
191
getByType : getByType ( instance ) ,
180
192
getByText : getByText ( instance ) ,
181
193
getByPlaceholder : getByPlaceholder ( instance ) ,
182
194
getByProps : getByProps ( instance ) ,
195
+ getAllByTestId : getAllByTestId ( instance ) ,
183
196
getAllByName : getAllByName ( instance ) ,
184
197
getAllByType : getAllByType ( instance ) ,
185
198
getAllByText : getAllByText ( instance ) ,
Original file line number Diff line number Diff line change 7
7
getByText ,
8
8
getByPlaceholder ,
9
9
getByProps ,
10
+ getAllByTestId ,
10
11
getAllByName ,
11
12
getAllByType ,
12
13
getAllByText ,
@@ -121,13 +122,24 @@ export const queryAllByProps = (instance: ReactTestInstance) => (props: {
121
122
}
122
123
} ;
123
124
125
+ export const queryAllByTestId = ( instance : ReactTestInstance ) => (
126
+ testID : string
127
+ ) => {
128
+ try {
129
+ return getAllByTestId ( instance ) ( testID ) ;
130
+ } catch ( error ) {
131
+ return [ ] ;
132
+ }
133
+ } ;
134
+
124
135
export const queryByAPI = ( instance : ReactTestInstance ) => ( {
125
136
queryByTestId : queryByTestId ( instance ) ,
126
137
queryByName : queryByName ( instance ) ,
127
138
queryByType : queryByType ( instance ) ,
128
139
queryByText : queryByText ( instance ) ,
129
140
queryByPlaceholder : queryByPlaceholder ( instance ) ,
130
141
queryByProps : queryByProps ( instance ) ,
142
+ queryAllByTestId : queryAllByTestId ( instance ) ,
131
143
queryAllByName : queryAllByName ( instance ) ,
132
144
queryAllByType : queryAllByType ( instance ) ,
133
145
queryAllByText : queryAllByText ( instance ) ,
You can’t perform that action at this time.
0 commit comments