Skip to content

Commit 410c6ed

Browse files
author
Kent C. Dodds
committed
WIP: I forgot about this... Will come back later
1 parent f12e0f2 commit 410c6ed

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/__tests__/get-by-errors.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,45 @@ cases(
4242
},
4343
},
4444
)
45+
46+
cases(
47+
'queryBy* queries throw an error when there are multiple elements returned',
48+
({name, query, html}) => {
49+
const utils = render(html)
50+
expect(() => utils[name](query)).toThrow(/multiple elements/i)
51+
},
52+
{
53+
queryByLabelText: {
54+
query: /his/,
55+
html: `<div aria-label="his"></div><div aria-label="history"></div>`,
56+
},
57+
queryByPlaceholderText: {
58+
query: /his/,
59+
html: `<input placeholder="his" /><input placeholder="history" />`,
60+
},
61+
queryByText: {
62+
query: /his/,
63+
html: `<div>his</div><div>history</div>`,
64+
},
65+
queryByAltText: {
66+
query: /his/,
67+
html: `<img alt="his" src="his.png" /><img alt="history" src="history.png" />`,
68+
},
69+
queryByTitle: {
70+
query: /his/,
71+
html: `<div title="his"></div><div title="history"></div>`,
72+
},
73+
queryByDisplayValue: {
74+
query: /his/,
75+
html: `<input value="his" /><select><option value="history">history</option></select>`,
76+
},
77+
queryByRole: {
78+
query: /his/,
79+
html: `<div role="his"></div><div role="history"></div>`,
80+
},
81+
queryByTestId: {
82+
query: /his/,
83+
html: `<div data-testid="his"></div><div data-testid="history"></div>`,
84+
},
85+
},
86+
)

0 commit comments

Comments
 (0)