Skip to content

Commit a1822d4

Browse files
committed
Tests accessible name in error for multiple found
1 parent 600f9b5 commit a1822d4

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

src/__tests__/role.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ Here are the accessible roles:
346346
test('has no useful error message in findBy', async () => {
347347
const {findByRole} = render(`<li />`)
348348

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+
)
350352
})
351353

352354
test('explicit role is most specific', () => {
@@ -378,6 +380,49 @@ Here are the accessible roles:
378380
`)
379381
})
380382

383+
test('accessible name in error message for multiple found', () => {
384+
const {getByRole} = render(`
385+
<div>
386+
<button> Increment value </button>
387+
<button> Decrement value </button>
388+
<button> Reset value </button>
389+
</div>
390+
`)
391+
392+
expect(() => getByRole('button', {name: /value/i}))
393+
.toThrowErrorMatchingInlineSnapshot(`
394+
"Found multiple elements with the role "button" and name \`/value/i\`
395+
396+
(If this is intentional, then use the \`*AllBy*\` variant of the query (like \`queryAllByText\`, \`getAllByText\`, or \`findAllByText\`)).
397+
398+
<div>
399+
400+
401+
<div>
402+
403+
404+
<button>
405+
Increment value
406+
</button>
407+
408+
409+
<button>
410+
Decrement value
411+
</button>
412+
413+
414+
<button>
415+
Reset value
416+
</button>
417+
418+
419+
</div>
420+
421+
422+
</div>"
423+
`)
424+
})
425+
381426
describe('configuration', () => {
382427
let originalConfig
383428
beforeEach(() => {

0 commit comments

Comments
 (0)