testing-library / dom-testing-library

🐙 Simple and complete DOM testing utilities that encourage good testing practices.

Home Page:https://testing-library.com/dom

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`alt` attribute can't be empty

Tasiobg opened this issue · comments

Since this update #1241 the alt attribute for the img role can't be empty.
My understanding is that the alt attribute should be present but in some cases like decorative images it should be empty, some info here

Is this an issue or an intended change?

Works

it(`testcase`, async () => {
    render(
      <div>
        <img src="url" alt="alt text" />
      </div>,
    );

    expect(screen.getByRole('img')).toBeInTheDocument();
  });

Fail

it(`testcase`, async () => {
    render(
      <div>
        <img src="url" alt="" />
      </div>,
    );

    expect(screen.getByRole('img')).toBeInTheDocument();
  });

Hi @Tasiobg :)
An image with an empty alt attribute has a role of none or presentation (based on the ARIA spec):
image

So this works as expected.
Thanks for the report.