diff --git a/src/__tests__/suggestions.js b/src/__tests__/suggestions.js index 5cbb94a0..3bb5364d 100644 --- a/src/__tests__/suggestions.js +++ b/src/__tests__/suggestions.js @@ -232,6 +232,16 @@ test('should suggest getByLabelText when no role available', () => { ) }) +it('should not suggest by label when using by label', async () => { + renderIntoDocument( + ``, + ) + + // 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(`
diff --git a/src/queries/label-text.js b/src/queries/label-text.js index b4a45cc6..083cd263 100644 --- a/src/queries/label-text.js +++ b/src/queries/label-text.js @@ -169,7 +169,7 @@ const findAllByLabelText = makeFindQuery( ), ) const findByLabelText = makeFindQuery( - wrapSingleQueryWithSuggestion(getByLabelText, getByLabelText.name, 'find'), + wrapSingleQueryWithSuggestion(getByLabelText, getAllByLabelText.name, 'find'), ) const getAllByLabelTextWithSuggestions = wrapAllByQueryWithSuggestion(