@@ -27,6 +27,15 @@ test('`checked` throws on unsupported roles', () => {
2727 )
2828} )
2929
30+ test ( '`expanded` throws on unsupported roles' , ( ) => {
31+ const { getByRole} = render ( `<h1 aria-expanded="true">Heading</h1>` )
32+ expect ( ( ) =>
33+ getByRole ( 'heading' , { expanded : true } ) ,
34+ ) . toThrowErrorMatchingInlineSnapshot (
35+ `"\\"aria-expanded\\" is not supported on role \\"heading\\"."` ,
36+ )
37+ } )
38+
3039test ( '`checked: true|false` matches `checked` checkboxes' , ( ) => {
3140 const { getByRole} = renderIntoDocument (
3241 `<div>
@@ -202,3 +211,25 @@ test('`level` throws on unsupported roles', () => {
202211 `"Role \\"button\\" cannot have \\"level\\" property."` ,
203212 )
204213} )
214+
215+ test ( '`expanded: true|false` matches `expanded` buttons' , ( ) => {
216+ const { getByRole} = renderIntoDocument (
217+ `<div>
218+ <button aria-expanded="true" />
219+ <button aria-expanded="false" />
220+ </div>` ,
221+ )
222+ expect ( getByRole ( 'button' , { expanded : true } ) ) . toBeInTheDocument ( )
223+ expect ( getByRole ( 'button' , { expanded : false } ) ) . toBeInTheDocument ( )
224+ } )
225+
226+ test ( '`expanded: true|false` matches `expanded` elements with proper role' , ( ) => {
227+ const { getByRole} = renderIntoDocument (
228+ `<div>
229+ <span role="button" aria-expanded="true">✔</span>
230+ <span role="button" aria-expanded="false">𝒙</span>
231+ </div>` ,
232+ )
233+ expect ( getByRole ( 'button' , { expanded : true } ) ) . toBeInTheDocument ( )
234+ expect ( getByRole ( 'button' , { expanded : false } ) ) . toBeInTheDocument ( )
235+ } )
0 commit comments