Skip to content

Commit 418d4fa

Browse files
committed
Lifts suggestion printing up one level
1 parent 1809549 commit 418d4fa

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/queries/role.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
} from '../role-helpers'
1010
import {wrapAllByQueryWithSuggestion} from '../query-helpers'
1111
import {checkContainerType} from '../helpers'
12-
import {prettyDOM} from '../pretty-dom'
1312
import {
1413
buildQueries,
1514
fuzzyMatches,
@@ -108,11 +107,8 @@ function queryAllByRole(
108107
})
109108
}
110109

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}`
110+
const getMultipleError = (c, role) => {
111+
return `Found multiple elements with the role "${role}"`
116112
}
117113

118114
const getMissingError = (

src/query-helpers.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {prettyDOM} from './pretty-dom'
12
import {getSuggestedQuery} from './suggestions'
23
import {fuzzyMatches, matches, makeNormalizer} from './matches'
34
import {waitFor} from './wait-for'
@@ -45,8 +46,14 @@ function makeSingleQuery(allQuery, getMultipleError) {
4546
return (container, ...args) => {
4647
const els = allQuery(container, ...args)
4748
if (els.length > 1) {
49+
const elementStrings = els.map(element => prettyDOM(element)).join('\n\n')
50+
4851
throw getMultipleElementsFoundError(
49-
getMultipleError({container, elements: els}, ...args),
52+
`${getMultipleError(container, ...args)}
53+
54+
Here are the matching elements:
55+
56+
${elementStrings}`,
5057
container,
5158
)
5259
}

0 commit comments

Comments
 (0)