Skip to content

Commit

Permalink
Merge pull request #835 from testing-library/feature/fix-find-by-labe…
Browse files Browse the repository at this point in the history
…l-text-suggestion

fix(suggestions): don't suggest byLabelText when using byLabelText
  • Loading branch information
benmonro committed Nov 20, 2020
2 parents 010f8be + 53f29f7 commit c6e7a83
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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

0 comments on commit c6e7a83

Please sign in to comment.