@@ -551,16 +551,44 @@ test('should get the first label with aria-labelledby contains multiple ids', ()
551
551
} )
552
552
} )
553
553
554
- test ( 'should suggest hidden option if element is not in the accessibilty tree ' , ( ) => {
554
+ test ( 'should not suggest or warn about hidden element when suggested query is already used. ' , ( ) => {
555
555
console . warn . mockImplementation ( ( ) => { } )
556
556
557
- const { container } = renderIntoDocument ( `
557
+ renderIntoDocument ( `
558
558
<input type="text" aria-hidden=true />
559
559
` )
560
560
561
- expect (
562
- getSuggestedQuery ( container . querySelector ( 'input' ) , 'get' , 'role' ) ,
563
- ) . toMatchObject ( {
561
+ expect ( ( ) => screen . getByRole ( 'textbox' , { hidden : true } ) ) . not . toThrowError ( )
562
+ expect ( console . warn ) . not . toHaveBeenCalled ( )
563
+ } )
564
+ test ( 'should suggest and warn about if element is not in the accessibility tree' , ( ) => {
565
+ console . warn . mockImplementation ( ( ) => { } )
566
+
567
+ renderIntoDocument ( `
568
+ <input type="text" data-testid="foo" aria-hidden=true />
569
+ ` )
570
+
571
+ expect ( ( ) => screen . getByTestId ( 'foo' , { hidden : true } ) ) . toThrowError (
572
+ / g e t B y R o l e \( ' t e x t b o x ' , \{ h i d d e n : t r u e \} \) / ,
573
+ )
574
+ expect ( console . warn ) . toHaveBeenCalledWith (
575
+ expect . stringContaining ( `Element is inaccessible.` ) ,
576
+ )
577
+ } )
578
+
579
+ test ( 'should suggest hidden option if element is not in the accessibility tree' , ( ) => {
580
+ console . warn . mockImplementation ( ( ) => { } )
581
+
582
+ const { container} = renderIntoDocument ( `
583
+ <input type="text" data-testid="foo" aria-hidden=true />
584
+ ` )
585
+
586
+ const suggestion = getSuggestedQuery (
587
+ container . querySelector ( 'input' ) ,
588
+ 'get' ,
589
+ 'role' ,
590
+ )
591
+ expect ( suggestion ) . toMatchObject ( {
564
592
queryName : 'Role' ,
565
593
queryMethod : 'getByRole' ,
566
594
queryArgs : [ 'textbox' , { hidden : true } ] ,
@@ -569,6 +597,7 @@ test('should suggest hidden option if element is not in the accessibilty tree',
569
597
If you are using the aria-hidden prop, make sure this is the right choice for your case.
570
598
` ,
571
599
} )
600
+ suggestion . toString ( )
572
601
573
602
expect ( console . warn . mock . calls ) . toMatchInlineSnapshot ( `
574
603
Array [
0 commit comments