Skip to content

Commit 53f29f7

Browse files
committed
fix(suggestions): don't suggest byLabelText when using byLabelText
1 parent 010f8be commit 53f29f7

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/__tests__/suggestions.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@ test('should suggest getByLabelText when no role available', () => {
232232
)
233233
})
234234

235+
it('should not suggest by label when using by label', async () => {
236+
renderIntoDocument(
237+
`<label><span>bar</span><input type="password" title="foo" /></label>`,
238+
)
239+
240+
// if a suggestion is made, this call will throw, thus failing the test.
241+
const password = await screen.findByLabelText(/bar/i)
242+
expect(password).toHaveAttribute('type', 'password')
243+
})
244+
235245
test(`should suggest getByLabel on non form elements`, () => {
236246
renderIntoDocument(`
237247
<div data-testid="foo" aria-labelledby="section-one-header">

src/queries/label-text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ const findAllByLabelText = makeFindQuery(
169169
),
170170
)
171171
const findByLabelText = makeFindQuery(
172-
wrapSingleQueryWithSuggestion(getByLabelText, getByLabelText.name, 'find'),
172+
wrapSingleQueryWithSuggestion(getByLabelText, getAllByLabelText.name, 'find'),
173173
)
174174

175175
const getAllByLabelTextWithSuggestions = wrapAllByQueryWithSuggestion(

0 commit comments

Comments
 (0)