@@ -312,9 +312,9 @@ describe('Shared TextField behavior', () => {
312
312
${ 'v3 TextField' } | ${ TextField }
313
313
${ 'v3 TextArea' } | ${ TextArea }
314
314
${ 'v3 SearchField' } | ${ SearchField }
315
- ` ( '$Name supports description or error message' , ( { Component} ) => {
315
+ ` ( '$Name supports description or error message' , async ( { Component} ) => {
316
316
function Example ( props ) {
317
- let [ value , setValue ] = React . useState ( '0' ) ;
317
+ let [ value , setValue ] = React . useState ( 0 ) ;
318
318
let isValid = React . useMemo ( ( ) => / ^ \d $ / . test ( value ) , [ value ] ) ;
319
319
320
320
return (
@@ -337,7 +337,9 @@ describe('Shared TextField behavior', () => {
337
337
let input = tree . getByTestId ( testId ) ;
338
338
let helpText = tree . getByText ( 'Enter a single digit number.' ) ;
339
339
expect ( helpText ) . toHaveAttribute ( 'id' ) ;
340
- expect ( input ) . toHaveAttribute ( 'aria-describedby' , `${ helpText . id } ` ) ;
340
+ let validIcon = tree . getByRole ( 'img' , { 'aria-label' : '(valid)' } ) ;
341
+ expect ( validIcon ) . toHaveAttribute ( 'id' ) ;
342
+ expect ( input ) . toHaveAttribute ( 'aria-describedby' , `${ helpText . id } ${ validIcon . id } ` ) ;
341
343
expect ( input . value ) . toBe ( '0' ) ;
342
344
let newValue = 's' ;
343
345
fireEvent . change ( input , { target : { value : newValue } } ) ;
@@ -353,10 +355,12 @@ describe('Shared TextField behavior', () => {
353
355
expect ( input ) . toHaveAttribute ( 'aria-describedby' , `${ helpText . id } ` ) ;
354
356
newValue = '4' ;
355
357
fireEvent . change ( input , { target : { value : newValue } } ) ;
356
- expect ( input . value ) . toBe ( newValue ) ;
358
+ expect ( input . value ) . toEqual ( '4' ) ;
357
359
helpText = tree . getByText ( 'Enter a single digit number.' ) ;
358
360
expect ( helpText ) . toHaveAttribute ( 'id' ) ;
359
- expect ( input ) . toHaveAttribute ( 'aria-describedby' , `${ helpText . id } ` ) ;
361
+ validIcon = tree . getByRole ( 'img' , { 'aria-label' : '(valid)' } ) ;
362
+ expect ( validIcon ) . toHaveAttribute ( 'id' ) ;
363
+ expect ( input ) . toHaveAttribute ( 'aria-describedby' , `${ helpText . id } ${ validIcon . id } ` ) ;
360
364
} ) ;
361
365
362
366
it . each `
@@ -387,7 +391,10 @@ describe('Shared TextField behavior', () => {
387
391
let tree = renderComponent ( Example ) ;
388
392
let input = tree . getByTestId ( testId ) ;
389
393
let helpText ;
390
- expect ( tree . getByTestId ( testId ) ) . not . toHaveAttribute ( 'aria-describedby' ) ;
394
+ let validIcon = tree . queryByRole ( 'img' , { 'aria-label' : '(valid)' } ) ;
395
+ expect ( validIcon ) . toBeTruthy ( ) ;
396
+ expect ( validIcon ) . toHaveAttribute ( 'id' ) ;
397
+ expect ( tree . getByTestId ( testId ) ) . toHaveAttribute ( 'aria-describedby' , `${ validIcon . id } ` ) ;
391
398
392
399
fireEvent . change ( input , { target : { value : 's' } } ) ;
393
400
@@ -418,7 +425,11 @@ describe('Shared TextField behavior', () => {
418
425
expect ( input . value ) . toEqual ( '4' ) ;
419
426
} ) ;
420
427
421
- expect ( input ) . not . toHaveAttribute ( 'aria-describedby' ) ;
428
+ validIcon = tree . getByRole ( 'img' , { 'aria-label' : '(valid)' } ) ;
429
+ expect ( validIcon ) . toBeTruthy ( ) ;
430
+ expect ( validIcon ) . toHaveAttribute ( 'id' ) ;
431
+
432
+ expect ( input ) . toHaveAttribute ( 'aria-describedby' , `${ validIcon . id } ` ) ;
422
433
} ) ;
423
434
424
435
it . each `
0 commit comments