Skip to content

Commit 5717c9c

Browse files
committed
test(a11y): assert img not accessible when missing "alt" attr
1 parent e04ad86 commit 5717c9c

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

packages/render-html/src/__tests__/component.render-html-a11y.test.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('RenderHTML a11y', () => {
7373
});
7474
});
7575
describe('regarding images', () => {
76-
it('should provide accessibility properties to <img> renderer', async () => {
76+
it('should provide accessibility properties to <img> renderer when alt attribute is defined', async () => {
7777
const element = (
7878
<RenderHTML
7979
source={{
@@ -88,6 +88,29 @@ describe('RenderHTML a11y', () => {
8888
const image = getByA11yRole('image');
8989
expect(image).toHaveProp('accessibilityRole', 'image');
9090
expect(image).toHaveProp('accessibilityLabel', 'An image');
91+
92+
// Waiting for AccessibilityEngine to support async udpates
93+
// see https://github.com/aryella-lacerda/react-native-accessibility-engine/issues/97
94+
// await waitFor(() =>
95+
// expect(() => AccessibilityEngine.check(element)).not.toThrow()
96+
// );
97+
});
98+
it('<img> should not be accessible when alt attribute is missing', async () => {
99+
const element = (
100+
<RenderHTML
101+
source={{
102+
html: '<img src="https://img.com/1x1" />'
103+
}}
104+
debug={false}
105+
contentWidth={200}
106+
/>
107+
);
108+
const { getByTestId, findByTestId } = render(element);
109+
await findByTestId('image-success');
110+
const image = getByTestId('img');
111+
expect(image).toHaveProp('accessibilityRole', 'none');
112+
expect(image).not.toHaveProp('accessibilityLabel');
113+
91114
// Waiting for AccessibilityEngine to support async udpates
92115
// see https://github.com/aryella-lacerda/react-native-accessibility-engine/issues/97
93116
// await waitFor(() =>

packages/render-html/src/__tests__/regression.377.classes-styles-re-render.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import { StyleSheet } from 'react-native';
32
import HTML from '../RenderHTML';
43
import { render } from '@testing-library/react-native';
54

0 commit comments

Comments
 (0)