@@ -551,16 +551,44 @@ test('should get the first label with aria-labelledby contains multiple ids', ()
551551 } )
552552} )
553553
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. ' , ( ) => {
555555 console . warn . mockImplementation ( ( ) => { } )
556556
557- const { container } = renderIntoDocument ( `
557+ renderIntoDocument ( `
558558 <input type="text" aria-hidden=true />
559559 ` )
560560
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 ( {
564592 queryName : 'Role' ,
565593 queryMethod : 'getByRole' ,
566594 queryArgs : [ 'textbox' , { hidden : true } ] ,
@@ -569,6 +597,7 @@ test('should suggest hidden option if element is not in the accessibilty tree',
569597 If you are using the aria-hidden prop, make sure this is the right choice for your case.
570598 ` ,
571599 } )
600+ suggestion . toString ( )
572601
573602 expect ( console . warn . mock . calls ) . toMatchInlineSnapshot ( `
574603 Array [
0 commit comments