Skip to content

Commit 1809549

Browse files
committed
Lists elements that matched multiple error
1 parent 373dbc4 commit 1809549

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/queries/role.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from '../role-helpers'
1010
import {wrapAllByQueryWithSuggestion} from '../query-helpers'
1111
import {checkContainerType} from '../helpers'
12+
import {prettyDOM} from '../pretty-dom'
1213
import {
1314
buildQueries,
1415
fuzzyMatches,
@@ -107,8 +108,12 @@ function queryAllByRole(
107108
})
108109
}
109110

110-
const getMultipleError = (c, role) =>
111-
`Found multiple elements with the role "${role}"`
111+
const getMultipleError = ({elements}, role) => {
112+
const suggestions = elements.map(element => prettyDOM(element)).join('\n')
113+
114+
return `Found multiple elements with the role "${role}"
115+
${suggestions}`
116+
}
112117

113118
const getMissingError = (
114119
container,

src/query-helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function makeSingleQuery(allQuery, getMultipleError) {
4646
const els = allQuery(container, ...args)
4747
if (els.length > 1) {
4848
throw getMultipleElementsFoundError(
49-
getMultipleError(container, ...args),
49+
getMultipleError({container, elements: els}, ...args),
5050
container,
5151
)
5252
}

0 commit comments

Comments
 (0)