Skip to content

Commit ef54f74

Browse files
rubennortemeta-codesync[bot]
authored andcommitted
Extend Image Fantom tests for alt, aria-label and prefetchWithMetadata (#57549)
Summary: Pull Request resolved: #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
1 parent 8149e22 commit ef54f74

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

packages/react-native/Libraries/Image/__tests__/Image-itest.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,34 @@ describe('<Image>', () => {
620620
});
621621
});
622622

623+
describe('alt', () => {
624+
it('is passed as accessibilityLabel and marks the image accessible', () => {
625+
const root = Fantom.createRoot();
626+
Fantom.runTask(() => {
627+
root.render(<Image alt="a picture" source={LOGO_SOURCE} />);
628+
});
629+
expect(
630+
root
631+
.getRenderedOutput({props: ['accessibilityLabel', 'accessible']})
632+
.toJSX(),
633+
).toEqual(
634+
<rn-image accessibilityLabel="a picture" accessible="true" />,
635+
);
636+
});
637+
});
638+
639+
describe('aria-label', () => {
640+
it('is passed as accessibilityLabel', () => {
641+
const root = Fantom.createRoot();
642+
Fantom.runTask(() => {
643+
root.render(<Image aria-label="labelled" source={LOGO_SOURCE} />);
644+
});
645+
expect(
646+
root.getRenderedOutput({props: ['accessibilityLabel']}).toJSX(),
647+
).toEqual(<rn-image accessibilityLabel="labelled" />);
648+
});
649+
});
650+
623651
component TestComponent(testID?: ?string, ...props: AccessibilityProps) {
624652
return <Image {...props} testID={testID} source={LOGO_SOURCE} />;
625653
}
@@ -1047,6 +1075,24 @@ describe('<Image>', () => {
10471075
});
10481076
});
10491077

1078+
describe('prefetchWithMetadata', () => {
1079+
it('prefetches the image', () => {
1080+
const uri = 'https://reactnative.dev/img/tiny_logo.png';
1081+
1082+
NativeFantom.setImageResponse(uri, {
1083+
width: 100,
1084+
height: 100,
1085+
});
1086+
1087+
let result;
1088+
Fantom.runTask(async () => {
1089+
result = await Image.prefetchWithMetadata(uri, 'queryRootName');
1090+
});
1091+
1092+
expect(result).toEqual(true);
1093+
});
1094+
});
1095+
10501096
describe('queryCache', () => {
10511097
it('returns empty when image is not cached', () => {
10521098
const uri = 'https://reactnative.dev/img/tiny_logo.png';

0 commit comments

Comments
 (0)