Skip to content

[findByLabelText] Adds a bad example using for w/ a non-form element #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2020

Conversation

sharmilajesupaul
Copy link
Contributor

@sharmilajesupaul sharmilajesupaul commented Jul 27, 2020

This came up at my work today.

An engineer thought that a for attr on a <label> along with a related <section> id can be queried by findByLabelText.

But really, this is not semantically correct and we end up with this error:

Timed out retrying: Found a label with the text of: Photos, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly.

I think making that explicit in the docs would avoid future confusion.

This came up at my work today. An engineer thought that a `for` attr on a `<label>` along with a related `<section>` `id` can be queried by `findByLabelText`.

But really, we end up with this error:
```
Timed out retrying: Found a label with the text of: Photos, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly.
```

I think making that explicit in the docs would avoid future confusion.
Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Thanks!

@kentcdodds kentcdodds merged commit 1dc5f28 into testing-library:master Jul 28, 2020
@kentcdodds
Copy link
Member

@all-contributors please add @sharmilajesupaul for docs

@allcontributors
Copy link
Contributor

@kentcdodds

I've put up a pull request to add @sharmilajesupaul! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants