@@ -40,6 +40,15 @@ export const getByName = (instance: ReactTestInstance) =>
40
40
}
41
41
} ;
42
42
43
+ export const getByType = ( instance : ReactTestInstance ) =>
44
+ function getByTypeFn ( type : React . ComponentType < * > ) {
45
+ try {
46
+ return instance . findByType ( type ) ;
47
+ } catch ( error ) {
48
+ throw new ErrorWithStack ( prepareErrorMessage ( error ) , getByTypeFn ) ;
49
+ }
50
+ } ;
51
+
43
52
export const getByText = ( instance : ReactTestInstance ) =>
44
53
function getByTextFn ( text : string | RegExp ) {
45
54
try {
@@ -80,6 +89,15 @@ export const getAllByName = (instance: ReactTestInstance) =>
80
89
return results ;
81
90
} ;
82
91
92
+ export const getAllByType = ( instance : ReactTestInstance ) =>
93
+ function getAllByTypeFn ( type : React . ComponentType < * > ) {
94
+ const results = instance . findAllByType ( type ) ;
95
+ if ( results . length === 0 ) {
96
+ throw new ErrorWithStack ( 'No instances found' , getAllByTypeFn ) ;
97
+ }
98
+ return results ;
99
+ } ;
100
+
83
101
export const getAllByText = ( instance : ReactTestInstance ) =>
84
102
function getAllByTextFn ( text : string | RegExp ) {
85
103
const results = instance . findAll ( node => getNodeByText ( node , text ) ) ;
@@ -107,9 +125,11 @@ export const getAllByProps = (instance: ReactTestInstance) =>
107
125
export const getByAPI = ( instance : ReactTestInstance ) => ( {
108
126
getByTestId : getByTestId ( instance ) ,
109
127
getByName : getByName ( instance ) ,
128
+ getByType : getByType ( instance ) ,
110
129
getByText : getByText ( instance ) ,
111
130
getByProps : getByProps ( instance ) ,
112
131
getAllByName : getAllByName ( instance ) ,
132
+ getAllByType : getAllByType ( instance ) ,
113
133
getAllByText : getAllByText ( instance ) ,
114
134
getAllByProps : getAllByProps ( instance ) ,
115
135
} ) ;
0 commit comments