@@ -10,25 +10,41 @@ import type {
10
10
QueryByQuery ,
11
11
} from './makeQueries' ;
12
12
13
+ /**
14
+ * Default accessibility state values based on experiments using accessibility
15
+ * inspector/screen reader on iOS and Android.
16
+ *
17
+ * @see https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State
18
+ */
19
+ const defaultState : AccessibilityState = {
20
+ disabled : false ,
21
+ selected : false ,
22
+ checked : undefined ,
23
+ busy : false ,
24
+ expanded : undefined ,
25
+ } ;
26
+
13
27
export function matchAccessibilityState (
14
28
node : ReactTestInstance ,
15
29
matcher : AccessibilityState
16
30
) {
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
31
+ const state = node . props . accessibilityState ;
21
32
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 )
33
+ matchState ( state , matcher , 'disabled' ) &&
34
+ matchState ( state , matcher , 'selected' ) &&
35
+ matchState ( state , matcher , 'checked' ) &&
36
+ matchState ( state , matcher , 'busy' ) &&
37
+ matchState ( state , matcher , ' expanded' )
27
38
) ;
28
39
}
29
40
30
- function matchState ( value : unknown , matcher : unknown ) {
31
- return matcher === undefined || value === matcher ;
41
+ function matchState (
42
+ value : AccessibilityState ,
43
+ matcher : AccessibilityState ,
44
+ key : keyof AccessibilityState
45
+ ) {
46
+ const valueWithDefault = value ?. [ key ] ?? defaultState [ key ] ;
47
+ return matcher [ key ] === undefined || matcher [ key ] === valueWithDefault ;
32
48
}
33
49
34
50
const queryAllByA11yState = (
0 commit comments