Skip to content

ByAltText examples seem incorrect #116

Closed
@bjohn465

Description

@bjohn465

Describe the bug
The example for ByAltText uses the following example markup:

<img alt="Incredibles 2 Poster" src="/incredibles-2.png" />

The examples pass /incredibles.*png$/i to getByAltText, which seems incorrect. If we're trying to find the element by the value of the alt attribute, why would we include png$ in the regular expression, since that's part of the src attribute and not the alt attribute?

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://testing-library.com/docs/dom-testing-library/api-queries#byalttext
  2. Scroll down to the ByAltText example, if it isn't already visible
  3. Look at the example code

Expected behavior
I would expect the example to use "Incredibles 2 Poster", /incredibles/i, or something without the "png" as the argument to getByAltText.

If /incredibles.*png$/i is somehow correct, then perhaps a note explaining why that works would be helpful.

Screenshots
image

Desktop (please complete the following information):
N/A

Smartphone (please complete the following information):
N/A

Additional context
I haven't used this library yet, so maybe /incredibles.*png$/i is perfectly valid here. If it is, it is confusing, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions