1
1
import type { ReactTestInstance } from 'react-test-renderer' ;
2
+ import type { AccessibilityRole , Role } from 'react-native' ;
2
3
import {
3
4
accessibilityStateKeys ,
4
5
accessiblityValueKeys ,
@@ -28,6 +29,10 @@ import type {
28
29
} from './make-queries' ;
29
30
import { CommonQueryOptions } from './options' ;
30
31
32
+ // TS autocomplete trick
33
+ // Ref: https://github.com/microsoft/TypeScript/issues/29729#issuecomment-567871939
34
+ export type RoleMatcher = AccessibilityRole | Role | ( string & { } ) | RegExp ;
35
+
31
36
type ByRoleOptions = CommonQueryOptions &
32
37
AccessibilityStateMatcher & {
33
38
name ?: TextMatch ;
@@ -52,7 +57,7 @@ const matchAccessibilityValueIfNeeded = (
52
57
return value != null ? matchAccessibilityValue ( node , value ) : true ;
53
58
} ;
54
59
55
- const queryAllByRole = ( instance : ReactTestInstance ) : QueryAllByQuery < TextMatch , ByRoleOptions > =>
60
+ const queryAllByRole = ( instance : ReactTestInstance ) : QueryAllByQuery < RoleMatcher , ByRoleOptions > =>
56
61
function queryAllByRoleFn ( role , options ) {
57
62
return findAll (
58
63
instance ,
@@ -102,12 +107,12 @@ const { getBy, getAllBy, queryBy, queryAllBy, findBy, findAllBy } = makeQueries(
102
107
) ;
103
108
104
109
export type ByRoleQueries = {
105
- getByRole : GetByQuery < TextMatch , ByRoleOptions > ;
106
- getAllByRole : GetAllByQuery < TextMatch , ByRoleOptions > ;
107
- queryByRole : QueryByQuery < TextMatch , ByRoleOptions > ;
108
- queryAllByRole : QueryAllByQuery < TextMatch , ByRoleOptions > ;
109
- findByRole : FindByQuery < TextMatch , ByRoleOptions > ;
110
- findAllByRole : FindAllByQuery < TextMatch , ByRoleOptions > ;
110
+ getByRole : GetByQuery < RoleMatcher , ByRoleOptions > ;
111
+ getAllByRole : GetAllByQuery < RoleMatcher , ByRoleOptions > ;
112
+ queryByRole : QueryByQuery < RoleMatcher , ByRoleOptions > ;
113
+ queryAllByRole : QueryAllByQuery < RoleMatcher , ByRoleOptions > ;
114
+ findByRole : FindByQuery < RoleMatcher , ByRoleOptions > ;
115
+ findAllByRole : FindAllByQuery < RoleMatcher , ByRoleOptions > ;
111
116
} ;
112
117
113
118
export const bindByRoleQueries = ( instance : ReactTestInstance ) : ByRoleQueries => ( {
0 commit comments