You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Images with an empty alt attribute are not being assigned presentation role (and are still being found by testing library even though they are hidden from the accessibility tree) #1290
importReactfrom'react'import{render,screen}from'@testing-library/react'import{ImageWithEmptyAlt}from'../'test('ImageWithEmptyAlt should not render an img role because the img has alt="" - this fails',()=>{render(<ImageWithEmptyAlt/>)expect(screen.queryByRole('img')).not.toBeInTheDocument();});test('ImageWithEmptyAlt should render presentation role because the img has alt="" - this fails',()=>{render(<ImageWithEmptyAlt/>)expect(screen.getByRole('presentation')).toBeInTheDocument();});
#1235 suggests that an img with an empty alt attribute should be given a presentation role:
According to the ARIA docs an img should only default to the role of presentation if it has an alt attribute equal to "":
Additionally, given that an image with alt="" removes it from the accessibility tree (screenreader users can't access it), I would expect that testing library should not be able to find it unless I include hidden: true in the query.
The fact that the test "finds" the image when a screenreader user would not reduces our confidence that the automation is behaving correctly.
Suggested solution:
Not sure, it seems like a bug here but would need the maintainers to confirm!
Thank you!