Extend Image Fantom tests for alt, aria-label and prefetchWithMetadata (#57549)

Summary:
Pull Request resolved: https://github.com/react/react-native/pull/57549

Extends `Image-itest.js` with coverage for public `Image` APIs that were previously untested, all exercised through the public `react-native` surface:
- the `alt` prop, which maps to `accessibilityLabel` and marks the image accessible;
- the `aria-label` prop, which maps to `accessibilityLabel`; and
- the `Image.prefetchWithMetadata` static method.

Changelog:
[Internal]

Reviewed By: sammy-SC

Differential Revision: D111914101

fbshipit-source-id: c63aaf2df28af7853dc1d75b2ba5ea6fbed894bb
This commit is contained in:
Rubén Norte authored and meta-codesync[bot] committed 2026-07-14 14:33:44 -07:00
1 parent 8149e22f4f
commit ef54f74deb
1 file changed
+46
@@ -620,6 +620,34 @@ describe('<Image>', () => {
});
});
describe('alt', () => {
it('is passed as accessibilityLabel and marks the image accessible', () => {
const root = Fantom.createRoot();
Fantom.runTask(() => {
root.render(<Image alt="a picture" source={LOGO_SOURCE} />);
});
expect(
root
.getRenderedOutput({props: ['accessibilityLabel', 'accessible']})
.toJSX(),
).toEqual(
<rn-image accessibilityLabel="a picture" accessible="true" />,
);
});
});
describe('aria-label', () => {
it('is passed as accessibilityLabel', () => {
const root = Fantom.createRoot();
Fantom.runTask(() => {
root.render(<Image aria-label="labelled" source={LOGO_SOURCE} />);
});
expect(
root.getRenderedOutput({props: ['accessibilityLabel']}).toJSX(),
).toEqual(<rn-image accessibilityLabel="labelled" />);
});
});
component TestComponent(testID?: ?string, ...props: AccessibilityProps) {
return <Image {...props} testID={testID} source={LOGO_SOURCE} />;
}
@@ -1047,6 +1075,24 @@ describe('<Image>', () => {
});
});
describe('prefetchWithMetadata', () => {
it('prefetches the image', () => {
const uri = 'https://reactnative.dev/img/tiny_logo.png';
NativeFantom.setImageResponse(uri, {
width: 100,
height: 100,
});
let result;
Fantom.runTask(async () => {
result = await Image.prefetchWithMetadata(uri, 'queryRootName');
});
expect(result).toEqual(true);
});
});
describe('queryCache', () => {
it('returns empty when image is not cached', () => {
const uri = 'https://reactnative.dev/img/tiny_logo.png';