@@ -346,7 +346,9 @@ Here are the accessible roles:
346
346
test ( 'has no useful error message in findBy' , async ( ) => {
347
347
const { findByRole} = render ( `<li />` )
348
348
349
- await expect ( findByRole ( 'option' , { timeout : 1 } ) ) . rejects . toThrow ( 'Unable to find role="option"' )
349
+ await expect ( findByRole ( 'option' , { timeout : 1 } ) ) . rejects . toThrow (
350
+ 'Unable to find role="option"' ,
351
+ )
350
352
} )
351
353
352
354
test ( 'explicit role is most specific' , ( ) => {
@@ -378,6 +380,62 @@ Here are the accessible roles:
378
380
` )
379
381
} )
380
382
383
+ test ( 'accessible regex name in error message for multiple found' , ( ) => {
384
+ const { getByRole} = render (
385
+ `<button>Increment value</button
386
+ ><button>Decrement value</button
387
+ ><button>Reset value</button
388
+ >` ,
389
+ )
390
+
391
+ expect ( ( ) => getByRole ( 'button' , { name : / v a l u e / i} ) )
392
+ . toThrowErrorMatchingInlineSnapshot ( `
393
+ "Found multiple elements with the role "button" and name \`/value/i\`
394
+
395
+ (If this is intentional, then use the \`*AllBy*\` variant of the query (like \`queryAllByText\`, \`getAllByText\`, or \`findAllByText\`)).
396
+
397
+ <div>
398
+ <button>
399
+ Increment value
400
+ </button>
401
+ <button>
402
+ Decrement value
403
+ </button>
404
+ <button>
405
+ Reset value
406
+ </button>
407
+ </div>"
408
+ ` )
409
+ } )
410
+
411
+ test ( 'accessible string name in error message for multiple found' , ( ) => {
412
+ const { getByRole} = render (
413
+ `<button>Submit</button
414
+ ><button>Submit</button
415
+ ><button>Submit</button
416
+ >` ,
417
+ )
418
+
419
+ expect ( ( ) => getByRole ( 'button' , { name : 'Submit' } ) )
420
+ . toThrowErrorMatchingInlineSnapshot ( `
421
+ "Found multiple elements with the role "button" and name "Submit"
422
+
423
+ (If this is intentional, then use the \`*AllBy*\` variant of the query (like \`queryAllByText\`, \`getAllByText\`, or \`findAllByText\`)).
424
+
425
+ <div>
426
+ <button>
427
+ Submit
428
+ </button>
429
+ <button>
430
+ Submit
431
+ </button>
432
+ <button>
433
+ Submit
434
+ </button>
435
+ </div>"
436
+ ` )
437
+ } )
438
+
381
439
describe ( 'configuration' , ( ) => {
382
440
let originalConfig
383
441
beforeEach ( ( ) => {
0 commit comments