queryByLabelText
queryByLabelText is a query function in React Testing Library that returns the form control element associated with a given label text. It searches the rendered DOM for a label that matches the provided text and then returns the element the label controls. The lookup respects standard accessibility associations, such as a label with an htmlFor attribute matching the input id or a nested input inside the label.
Return value and behavior: queryByLabelText returns the matched element if exactly one match exists. It returns
Usage: It is commonly used to locate inputs, selects, textareas, and other labeled controls in tests. Example
Relation to other queries: queryByLabelText is one of the "query by" family, alongside getByLabelText and findByLabelText.
Limitations: It relies on proper label associations and may not locate controls that lack a visible or