Skip to content

Commit 686175a

Browse files
authored
fix(ByDisplayValue): improve warning message (#443)
1 parent 8a62d82 commit 686175a

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

src/__tests__/element-queries.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ test('get throws a useful error message', () => {
7979
`)
8080
expect(() => getByDisplayValue('LucyRicardo'))
8181
.toThrowErrorMatchingInlineSnapshot(`
82-
"Unable to find an element with the value: LucyRicardo.
82+
"Unable to find an element with the display value: LucyRicardo.
8383
8484
<div>
8585
<div />
@@ -745,7 +745,7 @@ test('get throws a useful error message without DOM in Cypress', () => {
745745
expect(() =>
746746
getByDisplayValue('LucyRicardo'),
747747
).toThrowErrorMatchingInlineSnapshot(
748-
`"Unable to find an element with the value: LucyRicardo."`,
748+
`"Unable to find an element with the display value: LucyRicardo."`,
749749
)
750750
})
751751

src/__tests__/get-by-errors.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ cases(
2828
query: /his/,
2929
html: `<div title="his"></div><div title="history"></div>`,
3030
},
31-
getByDisplayValue: {
32-
query: /his/,
33-
html: `<input value="his" /><select><option value="history">history</option></select>`,
34-
},
3531
getByRole: {
3632
query: /his/,
3733
html: `<div role="his"></div><div role="history"></div>`,
@@ -70,10 +66,6 @@ cases(
7066
query: /his/,
7167
html: `<div title="his"></div><div title="history"></div>`,
7268
},
73-
queryByDisplayValue: {
74-
query: /his/,
75-
html: `<input value="his" /><select><option value="history">history</option></select>`,
76-
},
7769
queryByRole: {
7870
query: /his/,
7971
html: `<div role="his"></div><div role="history"></div>`,
@@ -84,3 +76,22 @@ cases(
8476
},
8577
},
8678
)
79+
80+
describe('*ByDisplayValue queries throw an error when there are multiple elements returned', () => {
81+
test('getByDisplayValue', () => {
82+
const {getByDisplayValue} = render(
83+
`<input value="his" /><select><option value="history">history</option></select>`,
84+
)
85+
expect(() => getByDisplayValue(/his/)).toThrow(
86+
/multiple elements with the display value:/i,
87+
)
88+
})
89+
test('queryByDisplayValue', () => {
90+
const {queryByDisplayValue} = render(
91+
`<input value="his" /><select><option value="history">history</option></select>`,
92+
)
93+
expect(() => queryByDisplayValue(/his/)).toThrow(
94+
/multiple elements with the display value:/i,
95+
)
96+
})
97+
})

src/queries/display-value.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ function queryAllByDisplayValue(
3030
}
3131

3232
const getMultipleError = (c, value) =>
33-
`Found multiple elements with the value: ${value}.`
33+
`Found multiple elements with the display value: ${value}.`
3434
const getMissingError = (c, value) =>
35-
`Unable to find an element with the value: ${value}.`
35+
`Unable to find an element with the display value: ${value}.`
3636
const [
3737
queryByDisplayValue,
3838
getAllByDisplayValue,

0 commit comments

Comments
 (0)