@@ -40,6 +40,15 @@ export const getByName = (instance: ReactTestInstance) =>
4040 }
4141 } ;
4242
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+
4352export const getByText = ( instance : ReactTestInstance ) =>
4453 function getByTextFn ( text : string | RegExp ) {
4554 try {
@@ -80,6 +89,15 @@ export const getAllByName = (instance: ReactTestInstance) =>
8089 return results ;
8190 } ;
8291
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+
83101export const getAllByText = ( instance : ReactTestInstance ) =>
84102 function getAllByTextFn ( text : string | RegExp ) {
85103 const results = instance . findAll ( node => getNodeByText ( node , text ) ) ;
@@ -107,9 +125,11 @@ export const getAllByProps = (instance: ReactTestInstance) =>
107125export const getByAPI = ( instance : ReactTestInstance ) => ( {
108126 getByTestId : getByTestId ( instance ) ,
109127 getByName : getByName ( instance ) ,
128+ getByType : getByType ( instance ) ,
110129 getByText : getByText ( instance ) ,
111130 getByProps : getByProps ( instance ) ,
112131 getAllByName : getAllByName ( instance ) ,
132+ getAllByType : getAllByType ( instance ) ,
113133 getAllByText : getAllByText ( instance ) ,
114134 getAllByProps : getAllByProps ( instance ) ,
115135} ) ;
0 commit comments