4
4
Pressable ,
5
5
Text ,
6
6
TextInput ,
7
+ Image ,
7
8
TouchableOpacity ,
8
9
TouchableWithoutFeedback ,
9
10
View ,
@@ -17,11 +18,11 @@ const TEXT_LABEL = 'cool text';
17
18
const NO_MATCHES_TEXT : any = 'not-existent-element' ;
18
19
19
20
const getMultipleInstancesFoundMessage = ( value : string ) => {
20
- return `Found multiple elements with role: " ${ value } " ` ;
21
+ return `Found multiple elements with role: ${ value } ` ;
21
22
} ;
22
23
23
24
const getNoInstancesFoundMessage = ( value : string ) => {
24
- return `Unable to find an element with role: " ${ value } " ` ;
25
+ return `Unable to find an element with role: ${ value } ` ;
25
26
} ;
26
27
27
28
const Typography = ( { children, ...rest } : any ) => {
@@ -224,6 +225,15 @@ describe('supports name option', () => {
224
225
expect ( screen . getByRole ( 'header' , { name : 'About' } ) ) . toBe ( screen . getByTestId ( 'target-header' ) ) ;
225
226
expect ( screen . getByRole ( 'header' , { name : 'About' } ) . props . testID ) . toBe ( 'target-header' ) ;
226
227
} ) ;
228
+
229
+ test ( 'supports host Image element with "alt" prop' , ( ) => {
230
+ render ( < Image alt = "An elephant" testID = "image" /> ) ;
231
+
232
+ const expectedElement = screen . getByTestId ( 'image' ) ;
233
+ expect ( screen . getByRole ( 'img' , { name : 'An elephant' } ) ) . toBe ( expectedElement ) ;
234
+ expect ( screen . getByRole ( 'image' , { name : 'An elephant' } ) ) . toBe ( expectedElement ) ;
235
+ expect ( screen . getByRole ( / i m g / , { name : 'An elephant' } ) ) . toBe ( expectedElement ) ;
236
+ } ) ;
227
237
} ) ;
228
238
229
239
describe ( 'supports accessibility states' , ( ) => {
@@ -768,7 +778,7 @@ describe('error messages', () => {
768
778
render ( < View /> ) ;
769
779
770
780
expect ( ( ) => screen . getByRole ( 'button' ) ) . toThrowErrorMatchingInlineSnapshot ( `
771
- "Unable to find an element with role: " button"
781
+ "Unable to find an element with role: button
772
782
773
783
<View />"
774
784
` ) ;
@@ -778,7 +788,7 @@ describe('error messages', () => {
778
788
render ( < View /> ) ;
779
789
780
790
expect ( ( ) => screen . getByRole ( 'button' , { name : 'Save' } ) ) . toThrowErrorMatchingInlineSnapshot ( `
781
- "Unable to find an element with role: " button" , name: " Save"
791
+ "Unable to find an element with role: button, name: Save
782
792
783
793
<View />"
784
794
` ) ;
@@ -789,7 +799,7 @@ describe('error messages', () => {
789
799
790
800
expect ( ( ) => screen . getByRole ( 'button' , { name : 'Save' , disabled : true } ) )
791
801
. toThrowErrorMatchingInlineSnapshot ( `
792
- "Unable to find an element with role: " button" , name: " Save" , disabled state: true
802
+ "Unable to find an element with role: button, name: Save, disabled state: true
793
803
794
804
<View />"
795
805
` ) ;
@@ -800,7 +810,7 @@ describe('error messages', () => {
800
810
801
811
expect ( ( ) => screen . getByRole ( 'button' , { name : 'Save' , disabled : true , selected : true } ) )
802
812
. toThrowErrorMatchingInlineSnapshot ( `
803
- "Unable to find an element with role: " button" , name: " Save" , disabled state: true, selected state: true
813
+ "Unable to find an element with role: button, name: Save, disabled state: true, selected state: true
804
814
805
815
<View />"
806
816
` ) ;
@@ -811,7 +821,7 @@ describe('error messages', () => {
811
821
812
822
expect ( ( ) => screen . getByRole ( 'button' , { disabled : true } ) )
813
823
. toThrowErrorMatchingInlineSnapshot ( `
814
- "Unable to find an element with role: " button" , disabled state: true
824
+ "Unable to find an element with role: button, disabled state: true
815
825
816
826
<View />"
817
827
` ) ;
@@ -822,7 +832,7 @@ describe('error messages', () => {
822
832
823
833
expect ( ( ) => screen . getByRole ( 'adjustable' , { value : { min : 1 } } ) )
824
834
. toThrowErrorMatchingInlineSnapshot ( `
825
- "Unable to find an element with role: " adjustable" , min value: 1
835
+ "Unable to find an element with role: adjustable, min value: 1
826
836
827
837
<View />"
828
838
` ) ;
@@ -832,7 +842,7 @@ describe('error messages', () => {
832
842
value : { min : 1 , max : 2 , now : 1 , text : / h e l l o / } ,
833
843
} ) ,
834
844
) . toThrowErrorMatchingInlineSnapshot ( `
835
- "Unable to find an element with role: " adjustable" , min value: 1, max value: 2, now value: 1, text value: /hello/
845
+ "Unable to find an element with role: adjustable, min value: 1, max value: 2, now value: 1, text value: /hello/
836
846
837
847
<View />"
838
848
` ) ;
@@ -852,7 +862,7 @@ test('byRole queries support hidden option', () => {
852
862
expect ( screen . queryByRole ( 'button' , { includeHiddenElements : false } ) ) . toBeFalsy ( ) ;
853
863
expect ( ( ) => screen . getByRole ( 'button' , { includeHiddenElements : false } ) )
854
864
. toThrowErrorMatchingInlineSnapshot ( `
855
- "Unable to find an element with role: " button"
865
+ "Unable to find an element with role: button
856
866
857
867
<View
858
868
accessibilityRole="button"
@@ -889,7 +899,7 @@ describe('matches only accessible elements', () => {
889
899
expect ( screen . queryByRole ( 'button' , { name : 'Action' } ) ) . toBeFalsy ( ) ;
890
900
} ) ;
891
901
892
- test ( 'ignores elements with accessible={undefined} and that are implicitely not accessible' , ( ) => {
902
+ test ( 'ignores elements with accessible={undefined} and that are implicitly not accessible' , ( ) => {
893
903
render (
894
904
< View accessibilityRole = "menu" >
895
905
< Text > Action</ Text >
@@ -903,31 +913,31 @@ test('error message renders the element tree, preserving only helpful props', as
903
913
render ( < View accessibilityRole = "button" key = "3" /> ) ;
904
914
905
915
expect ( ( ) => screen . getByRole ( 'link' ) ) . toThrowErrorMatchingInlineSnapshot ( `
906
- "Unable to find an element with role: " link"
916
+ "Unable to find an element with role: link
907
917
908
918
<View
909
919
accessibilityRole="button"
910
920
/>"
911
921
` ) ;
912
922
913
923
expect ( ( ) => screen . getAllByRole ( 'link' ) ) . toThrowErrorMatchingInlineSnapshot ( `
914
- "Unable to find an element with role: " link"
924
+ "Unable to find an element with role: link
915
925
916
926
<View
917
927
accessibilityRole="button"
918
928
/>"
919
929
` ) ;
920
930
921
931
await expect ( screen . findByRole ( 'link' ) ) . rejects . toThrowErrorMatchingInlineSnapshot ( `
922
- "Unable to find an element with role: " link"
932
+ "Unable to find an element with role: link
923
933
924
934
<View
925
935
accessibilityRole="button"
926
936
/>"
927
937
` ) ;
928
938
929
939
await expect ( screen . findAllByRole ( 'link' ) ) . rejects . toThrowErrorMatchingInlineSnapshot ( `
930
- "Unable to find an element with role: " link"
940
+ "Unable to find an element with role: link
931
941
932
942
<View
933
943
accessibilityRole="button"
0 commit comments