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 8 months ago
Updated 6 months 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.

egghead
egghead
~ 15 minutes ago

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

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

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!

Markdown supported.
Become a member to join the discussionEnroll Today