1. 10
    Get Elements With a Given Text Match Using the byText Query
    43s

Get Elements With a Given Text Match Using the byText Query

Daniel Afonso
InstructorDaniel Afonso
Share this video with your friends

Social Share Links

Send Tweet
Published a year ago
Updated a year ago

Text is one of the main ways that the users of your page find what they are looking 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 really helpful when finding non-interactive elements: the byText query.

Instructor: [0:05] When learning the types of queries, you might remember that whoever joins specific query in all those examples. This was the ByText query. The ByText query is a query that belongs to the queries accessible to Everyone Family that allows you to find text contained in your UI.

[0:14] In most scenarios, you should resort to the queries mentioned in the lessons before, but let's imagine that like in our UI here, we have a p tag with text.

[0:23] None of the other queries would work here, so this is the perfect scenario for the ByText query. In our test case, let's destructure the getByText query from render, and then pass it the text we want to look for.

[0:34] In this scenario, this text is some random text. Finally, let's assert that this is indeed in the UI, and run our test. You should see that it has passed.