1
- import { render } from './helpers/test-utils'
1
+ import { render , renderIntoDocument } from './helpers/test-utils'
2
2
3
3
test ( '`selected` throws on unsupported roles' , ( ) => {
4
4
const { getByRole} = render ( `<input aria-selected="true" type="text">` )
@@ -9,6 +9,59 @@ test('`selected` throws on unsupported roles', () => {
9
9
)
10
10
} )
11
11
12
+ test ( '`checked` throws on unsupported roles' , ( ) => {
13
+ const { getByRole} = render ( `<input aria-checked="true" type="text">` )
14
+ expect ( ( ) =>
15
+ getByRole ( 'textbox' , { checked : true } ) ,
16
+ ) . toThrowErrorMatchingInlineSnapshot (
17
+ `"\\"aria-checked\\" is not supported on role \\"textbox\\"."` ,
18
+ )
19
+ } )
20
+
21
+ test ( '`checked: true|false` matches `checked` checkboxes' , ( ) => {
22
+ const { getByRole} = renderIntoDocument (
23
+ `<div>
24
+ <input type="checkbox" checked />
25
+ <input type="checkbox" />
26
+ </div>` ,
27
+ )
28
+ expect ( getByRole ( 'checkbox' , { checked : true } ) ) . toBeInTheDocument ( )
29
+ expect ( getByRole ( 'checkbox' , { checked : false } ) ) . toBeInTheDocument ( )
30
+ } )
31
+
32
+ test ( '`checked: true|false` matches `checked` elements with proper role' , ( ) => {
33
+ const { getByRole} = renderIntoDocument (
34
+ `<div>
35
+ <span role="checkbox" aria-checked="true">✔</span>
36
+ <span role="checkbox" aria-checked="false">𝒙</span>
37
+ </div>` ,
38
+ )
39
+ expect ( getByRole ( 'checkbox' , { checked : true } ) ) . toBeInTheDocument ( )
40
+ expect ( getByRole ( 'checkbox' , { checked : false } ) ) . toBeInTheDocument ( )
41
+ } )
42
+
43
+ test ( '`checked: true|false` does not match element in `indeterminate` state' , ( ) => {
44
+ const { queryByRole, getByLabelText} = renderIntoDocument (
45
+ `<div>
46
+ <span role="checkbox" aria-checked="mixed">not so much</span>
47
+ <input type="checkbox" checked aria-label="indeteminate yes" />
48
+ <input type="checkbox" aria-label="indeteminate no" />
49
+ </div>` ,
50
+ )
51
+ getByLabelText ( / i n d e t e m i n a t e y e s / i) . indeterminate = true
52
+ getByLabelText ( / i n d e t e m i n a t e n o / i) . indeterminate = true
53
+
54
+ expect (
55
+ queryByRole ( 'checkbox' , { checked : true , name : / i n d e t e m i n a t e y e s / i} ) ,
56
+ ) . toBeNull ( )
57
+ expect (
58
+ queryByRole ( 'checkbox' , { checked : false , name : / i n d e t e m i n a t e n o / i} ) ,
59
+ ) . toBeNull ( )
60
+ expect (
61
+ queryByRole ( 'checkbox' , { checked : true , name : / n o t s o m u c h / i} ) ,
62
+ ) . toBeNull ( )
63
+ } )
64
+
12
65
test ( '`selected: true` matches `aria-selected="true"` on supported roles' , ( ) => {
13
66
const { getAllByRole} = render ( `
14
67
<select>
0 commit comments