Sometimes your form might be missing a label. Whilst they are not a label replacement, placeholders can help give feedback about what that element should be for.
In this lesson, we will look at another one of the queries that are part of the queries accessible to everyone's family and also helpful when dealing with forms: the byPlaceholderText query.
Instructor: [0:00] While it does not replace the label, in some cases, you might find yourself with only a placeholder. Inside the queries accessible to everyone's family, the byPlaceholderText query is your go-to whenever dealing with form fields that lack a label.
[0:12] Looking at our component, we can find here an input with a default value and a placeholder. This input can be queried in several ways, but in this scenario, we'll go with the placeholder.
[0:22] Moving to our test case, let's destructure the getByPlaceholderText from Render. Then, we call getByPlaceholderText and pass the text that was on the placeholder, which in this case was inputPlaceholder.
[0:34] Then, we add our toBeInTheDocument assertion to make sure everything works, and if we run our test, we should see that it has passed.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!