diff --git a/src/__tests__/element-queries.js b/src/__tests__/element-queries.js index 99372a4d..561c0006 100644 --- a/src/__tests__/element-queries.js +++ b/src/__tests__/element-queries.js @@ -197,6 +197,19 @@ test('can get elements labelled with aria-labelledby attribute', () => { expect(getByLabelText('Section One').id).toBe('section-one') }) +test('can get sibling elements with aria-labelledby attrib ute', () => { + const {getAllByLabelText} = render(` +
+ + Tacos +
+ `) + + const result = getAllByLabelText('Tacos') + expect(result).toHaveLength(1) + expect(result[0].id).toBe('icon') +}) + test('get can get form controls by placeholder', () => { const {getByPlaceholderText} = render(` , diff --git a/src/queries/label-text.js b/src/queries/label-text.js index 7df781cd..2a3aee66 100644 --- a/src/queries/label-text.js +++ b/src/queries/label-text.js @@ -63,7 +63,7 @@ function queryAllByLabelText( const possibleAriaLabelElements = queryAllByText(container, text, { exact, normalizer: matchNormalizer, - }).filter(el => el.tagName !== 'LABEL') // don't reprocess labels + }) const ariaLabelledElements = possibleAriaLabelElements.reduce( (allLabelledElements, nextLabelElement) => {