Skip to content

fix(suggestions): don't suggest byLabelText when using byLabelText #835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2020
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
10 changes: 10 additions & 0 deletions src/__tests__/suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ test('should suggest getByLabelText when no role available', () => {
)
})

it('should not suggest by label when using by label', async () => {
renderIntoDocument(
`<label><span>bar</span><input type="password" title="foo" /></label>`,
)

// if a suggestion is made, this call will throw, thus failing the test.
const password = await screen.findByLabelText(/bar/i)
expect(password).toHaveAttribute('type', 'password')
})

test(`should suggest getByLabel on non form elements`, () => {
renderIntoDocument(`
<div data-testid="foo" aria-labelledby="section-one-header">
Expand Down
2 changes: 1 addition & 1 deletion src/queries/label-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const findAllByLabelText = makeFindQuery(
),
)
const findByLabelText = makeFindQuery(
wrapSingleQueryWithSuggestion(getByLabelText, getByLabelText.name, 'find'),
wrapSingleQueryWithSuggestion(getByLabelText, getAllByLabelText.name, 'find'),
)

const getAllByLabelTextWithSuggestions = wrapAllByQueryWithSuggestion(
Expand Down