1. 8
    Get Elements With a Given Placeholder Text Using the byPlaceholderText Query
    41s

Get Elements With a Given Placeholder Text Using the byPlaceholderText Query

Daniel Afonso
InstructorDaniel Afonso
Share this video with your friends

Social Share Links

Send Tweet

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.