Skip to content

Commit 4bcb210

Browse files
authored
Merge branch 'main' into feat/logTestingPlaygroundReturnValue
2 parents b65431d + 7b10f73 commit 4bcb210

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,15 @@
15351535
"contributions": [
15361536
"code"
15371537
]
1538+
},
1539+
{
1540+
"login": "dolevoper",
1541+
"name": "Omer Dolev",
1542+
"avatar_url": "https://avatars.githubusercontent.com/u/53278705?v=4",
1543+
"profile": "https://github.com/dolevoper",
1544+
"contributions": [
1545+
"code"
1546+
]
15381547
}
15391548
],
15401549
"repoHost": "https://github.com"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ Thanks goes to these people ([emoji key][emojis]):
333333
<td align="center"><a href="https://github.com/Dennis273"><img src="https://avatars.githubusercontent.com/u/19815164?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Dennis273</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=Dennis273" title="Code">💻</a></td>
334334
<td align="center"><a href="https://www.jacksonhardaker.dev"><img src="https://avatars.githubusercontent.com/u/7596320?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jackson Hardaker</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=jacksonhardaker" title="Tests">⚠️</a></td>
335335
<td align="center"><a href="https://www.robin-drexler.com/"><img src="https://avatars.githubusercontent.com/u/474248?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Robin Drexler</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=robin-drexler" title="Code">💻</a></td>
336+
<td align="center"><a href="https://github.com/dolevoper"><img src="https://avatars.githubusercontent.com/u/53278705?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Omer Dolev</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=dolevoper" title="Code">💻</a></td>
336337
</tr>
337338
</table>
338339

src/__tests__/role.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,14 @@ test('has no useful error message in findBy', async () => {
363363
)
364364
})
365365

366+
test('findBy error message for missing elements contains a name hint', async () => {
367+
const {findByRole} = render(`<button>Click me</button>`)
368+
369+
await expect(findByRole('button', {name: 'Submit'})).rejects.toThrow(
370+
'Unable to find role="button" and name "Submit"',
371+
)
372+
})
373+
366374
test('explicit role is most specific', () => {
367375
const {getByRole} = renderIntoDocument(
368376
`<button role="tab" aria-label="my-tab" />`,

src/queries/role.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ function makeRoleSelector(role, exact, customNormalizer) {
220220
.join(',')
221221
}
222222

223-
const getMultipleError = (c, role, {name} = {}) => {
223+
const getNameHint = name => {
224224
let nameHint = ''
225225
if (name === undefined) {
226226
nameHint = ''
@@ -230,7 +230,11 @@ const getMultipleError = (c, role, {name} = {}) => {
230230
nameHint = ` and name \`${name}\``
231231
}
232232

233-
return `Found multiple elements with the role "${role}"${nameHint}`
233+
return nameHint
234+
}
235+
236+
const getMultipleError = (c, role, {name} = {}) => {
237+
return `Found multiple elements with the role "${role}"${getNameHint(name)}`
234238
}
235239

236240
const getMissingError = (
@@ -239,7 +243,7 @@ const getMissingError = (
239243
{hidden = getConfig().defaultHidden, name, description} = {},
240244
) => {
241245
if (getConfig()._disableExpensiveErrorDiagnostics) {
242-
return `Unable to find role="${role}"`
246+
return `Unable to find role="${role}"${getNameHint(name)}`
243247
}
244248

245249
let roles = ''

0 commit comments

Comments
 (0)