@@ -10,6 +10,23 @@ import type {
10
10
QueryByQuery ,
11
11
} from './makeQueries' ;
12
12
13
+ export function matchAccessibilityState (
14
+ node : ReactTestInstance ,
15
+ matcher : AccessibilityState
16
+ ) {
17
+ const stateProp = node . props . accessibilityState ;
18
+
19
+ // busy, disabled & selected states default to false,
20
+ // while checked & expended states treat false and default as sepatate values
21
+ return (
22
+ matchState ( stateProp ?. busy ?? false , matcher . busy ) &&
23
+ matchState ( stateProp ?. disabled ?? false , matcher . disabled ) &&
24
+ matchState ( stateProp ?. selected ?? false , matcher . selected ) &&
25
+ matchState ( stateProp ?. checked , matcher . checked ) &&
26
+ matchState ( stateProp ?. expanded , matcher . expanded )
27
+ ) ;
28
+ }
29
+
13
30
function matchState ( value : unknown , matcher : unknown ) {
14
31
return matcher === undefined || value === matcher ;
15
32
}
@@ -19,17 +36,8 @@ const queryAllByA11yState = (
19
36
) : ( ( matcher : AccessibilityState ) => Array < ReactTestInstance > ) =>
20
37
function queryAllByA11yStateFn ( matcher ) {
21
38
return instance . findAll ( ( node ) => {
22
- const stateProp = node . props . accessibilityState ;
23
-
24
- // busy, disabled & selected states default to false,
25
- // while checked & expended states treat false and default as sepatate values
26
39
return (
27
- typeof node . type === 'string' &&
28
- matchState ( stateProp ?. busy ?? false , matcher . busy ) &&
29
- matchState ( stateProp ?. disabled ?? false , matcher . disabled ) &&
30
- matchState ( stateProp ?. selected ?? false , matcher . selected ) &&
31
- matchState ( stateProp ?. checked , matcher . checked ) &&
32
- matchState ( stateProp ?. expanded , matcher . expanded )
40
+ typeof node . type === 'string' && matchAccessibilityState ( node , matcher )
33
41
) ;
34
42
} ) ;
35
43
} ;
0 commit comments