Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/__tests__/element-queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ test('get throws a useful error message', () => {
`)
expect(() => getByDisplayValue('LucyRicardo'))
.toThrowErrorMatchingInlineSnapshot(`
"Unable to find an element with the value: LucyRicardo.
"Unable to find an element with the display value: LucyRicardo.

<div>
<div />
Expand Down Expand Up @@ -745,7 +745,7 @@ test('get throws a useful error message without DOM in Cypress', () => {
expect(() =>
getByDisplayValue('LucyRicardo'),
).toThrowErrorMatchingInlineSnapshot(
`"Unable to find an element with the value: LucyRicardo."`,
`"Unable to find an element with the display value: LucyRicardo."`,
)
})

Expand Down
27 changes: 19 additions & 8 deletions src/__tests__/get-by-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ cases(
query: /his/,
html: `<div title="his"></div><div title="history"></div>`,
},
getByDisplayValue: {
query: /his/,
html: `<input value="his" /><select><option value="history">history</option></select>`,
},
getByRole: {
query: /his/,
html: `<div role="his"></div><div role="history"></div>`,
Expand Down Expand Up @@ -70,10 +66,6 @@ cases(
query: /his/,
html: `<div title="his"></div><div title="history"></div>`,
},
queryByDisplayValue: {
query: /his/,
html: `<input value="his" /><select><option value="history">history</option></select>`,
},
queryByRole: {
query: /his/,
html: `<div role="his"></div><div role="history"></div>`,
Expand All @@ -84,3 +76,22 @@ cases(
},
},
)

describe('*ByDisplayValue queries throw an error when there are multiple elements returned', () => {
test('getByDisplayValue', () => {
const {getByDisplayValue} = render(
`<input value="his" /><select><option value="history">history</option></select>`,
)
expect(() => getByDisplayValue(/his/)).toThrow(
/multiple elements with the display value:/i,
)
})
test('queryByDisplayValue', () => {
const {queryByDisplayValue} = render(
`<input value="his" /><select><option value="history">history</option></select>`,
)
expect(() => queryByDisplayValue(/his/)).toThrow(
/multiple elements with the display value:/i,
)
})
})
4 changes: 2 additions & 2 deletions src/queries/display-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ function queryAllByDisplayValue(
}

const getMultipleError = (c, value) =>
`Found multiple elements with the value: ${value}.`
`Found multiple elements with the display value: ${value}.`
const getMissingError = (c, value) =>
`Unable to find an element with the value: ${value}.`
`Unable to find an element with the display value: ${value}.`
const [
queryByDisplayValue,
getAllByDisplayValue,
Expand Down