Skip to content

Commit f526e91

Browse files
andrewdacenkofacebook-github-bot
authored andcommitted
Add tests for src and srcSet (#53062)
Summary: Pull Request resolved: #53062 Changelog: [Internal] As title Reviewed By: rshest Differential Revision: D79642287 fbshipit-source-id: 59d7dbf7f2562ca550ac48eb9067469e6128e7c6
1 parent bb5d0df commit f526e91

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

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

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,127 @@ describe('<Image>', () => {
429429
);
430430
});
431431
});
432+
433+
describe('src', () => {
434+
it('can be set to a remote image', () => {
435+
const root = Fantom.createRoot();
436+
437+
Fantom.runTask(() => {
438+
root.render(
439+
<Image src="https://reactnative.dev/img/tiny_logo.png" />,
440+
);
441+
});
442+
443+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
444+
<rn-image
445+
source-scale="1"
446+
source-type="remote"
447+
source-uri="https://reactnative.dev/img/tiny_logo.png"
448+
/>,
449+
);
450+
});
451+
452+
it('takes precedence over `source` prop', () => {
453+
const root = Fantom.createRoot();
454+
455+
Fantom.runTask(() => {
456+
root.render(
457+
<Image
458+
src="https://reactnative.dev/img/tiny_logo.png"
459+
source={{uri: 'https://reactnative.dev/img/medium_logo.png'}}
460+
/>,
461+
);
462+
});
463+
464+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
465+
<rn-image
466+
source-scale="1"
467+
source-type="remote"
468+
source-uri="https://reactnative.dev/img/tiny_logo.png"
469+
/>,
470+
);
471+
});
472+
});
473+
474+
describe('srcSet', () => {
475+
it('can be set to a list of remote images', () => {
476+
const root = Fantom.createRoot();
477+
478+
Fantom.runTask(() => {
479+
root.render(
480+
<Image
481+
srcSet={
482+
'https://reactnative.dev/img/tiny_logo.png 1x, https://reactnative.dev/img/header_logo.svg 2x'
483+
}
484+
/>,
485+
);
486+
});
487+
488+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
489+
<rn-image
490+
source-1x-scale="1"
491+
source-1x-type="remote"
492+
source-1x-uri="https://reactnative.dev/img/tiny_logo.png"
493+
source-2x-scale="2"
494+
source-2x-type="remote"
495+
source-2x-uri="https://reactnative.dev/img/header_logo.svg"
496+
/>,
497+
);
498+
});
499+
500+
it('defaults to `1x` descriptor', () => {
501+
const root = Fantom.createRoot();
502+
503+
Fantom.runTask(() => {
504+
root.render(
505+
<Image
506+
srcSet={
507+
'https://reactnative.dev/img/tiny_logo.png, https://reactnative.dev/img/header_logo.svg 2x'
508+
}
509+
/>,
510+
);
511+
});
512+
513+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
514+
<rn-image
515+
source-1x-scale="1"
516+
source-1x-type="remote"
517+
source-1x-uri="https://reactnative.dev/img/tiny_logo.png"
518+
source-2x-scale="2"
519+
source-2x-type="remote"
520+
source-2x-uri="https://reactnative.dev/img/header_logo.svg"
521+
/>,
522+
);
523+
});
524+
525+
it('uses `src` for `1x` descriptor when provided', () => {
526+
const root = Fantom.createRoot();
527+
528+
Fantom.runTask(() => {
529+
root.render(
530+
<Image
531+
srcSet={
532+
'https://reactnative.dev/img/header_logo.svg 2x, https://reactnative.dev/img/large_logo.svg 3x'
533+
}
534+
src="https://reactnative.dev/img/tiny_logo.png"
535+
/>,
536+
);
537+
});
538+
539+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
540+
<rn-image
541+
source-1x-scale="1"
542+
source-1x-type="remote"
543+
source-1x-uri="https://reactnative.dev/img/tiny_logo.png"
544+
source-2x-scale="2"
545+
source-2x-type="remote"
546+
source-2x-uri="https://reactnative.dev/img/header_logo.svg"
547+
source-3x-type="remote"
548+
source-3x-uri="https://reactnative.dev/img/large_logo.svg"
549+
/>,
550+
);
551+
});
552+
});
432553
});
433554

434555
describe('ref', () => {

0 commit comments

Comments
 (0)