From 13b00eaf340b32ada3c05f7e6079a6dde23a5587 Mon Sep 17 00:00:00 2001 From: Aaron Pettengill Date: Wed, 4 Mar 2020 12:32:47 -0500 Subject: [PATCH] feat(ByLabelText): change selector to match target (not label) (#373) Closes #372 BREAKING CHANGE: If you used the `selector` option in `ByLabelText` queries, then you will probably need to update that code to be able to find the label you're looking for. --- src/__tests__/element-queries.js | 69 +++++++++++++++++++++++++++++++- src/queries/label-text.js | 31 +++++++++----- 2 files changed, 88 insertions(+), 12 deletions(-) diff --git a/src/__tests__/element-queries.js b/src/__tests__/element-queries.js index 72029c00..b0dc39c8 100644 --- a/src/__tests__/element-queries.js +++ b/src/__tests__/element-queries.js @@ -199,7 +199,7 @@ 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', () => { +test('can get sibling elements with aria-labelledby attribute', () => { const {getAllByLabelText} = render(`
@@ -212,6 +212,73 @@ test('can get sibling elements with aria-labelledby attrib ute', () => { expect(result[0].id).toBe('icon') }) +test('can filter results of label query based on selector', () => { + const {getAllByLabelText} = render(` +
+ + + Some hint text +
+ `) + + const result = getAllByLabelText('Test Label', {selector: '.fancy-input'}) + expect(result).toHaveLength(1) + expect(result[0].id).toBe('input1') +}) + +test('can find any form control when label text is inside other elements', () => { + const {getAllByLabelText} = render(` +