Skip to content

Commit f1ba170

Browse files
andrewdacenkofacebook-github-bot
authored andcommitted
Add tests for src and srcSet (facebook#53062)
Summary: Changelog: [Internal] As title Differential Revision: D79642287
1 parent a24ec30 commit f1ba170

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
@@ -383,6 +383,127 @@ describe('<Image>', () => {
383383
);
384384
});
385385
});
386+
387+
describe('src', () => {
388+
it('can be set to a remote image', () => {
389+
const root = Fantom.createRoot();
390+
391+
Fantom.runTask(() => {
392+
root.render(
393+
<Image src="https://reactnative.dev/img/tiny_logo.png" />,
394+
);
395+
});
396+
397+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
398+
<rn-image
399+
source-scale="1"
400+
source-type="remote"
401+
source-uri="https://reactnative.dev/img/tiny_logo.png"
402+
/>,
403+
);
404+
});
405+
406+
it('takes precedence over `source` prop', () => {
407+
const root = Fantom.createRoot();
408+
409+
Fantom.runTask(() => {
410+
root.render(
411+
<Image
412+
src="https://reactnative.dev/img/tiny_logo.png"
413+
source={{uri: 'https://reactnative.dev/img/medium_logo.png'}}
414+
/>,
415+
);
416+
});
417+
418+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
419+
<rn-image
420+
source-scale="1"
421+
source-type="remote"
422+
source-uri="https://reactnative.dev/img/tiny_logo.png"
423+
/>,
424+
);
425+
});
426+
});
427+
428+
describe('srcSet', () => {
429+
it('can be set to a list of remote images', () => {
430+
const root = Fantom.createRoot();
431+
432+
Fantom.runTask(() => {
433+
root.render(
434+
<Image
435+
srcSet={
436+
'https://reactnative.dev/img/tiny_logo.png 1x, https://reactnative.dev/img/header_logo.svg 2x'
437+
}
438+
/>,
439+
);
440+
});
441+
442+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
443+
<rn-image
444+
source-1x-scale="1"
445+
source-1x-type="remote"
446+
source-1x-uri="https://reactnative.dev/img/tiny_logo.png"
447+
source-2x-scale="2"
448+
source-2x-type="remote"
449+
source-2x-uri="https://reactnative.dev/img/header_logo.svg"
450+
/>,
451+
);
452+
});
453+
454+
it('defaults to `1x` descriptor', () => {
455+
const root = Fantom.createRoot();
456+
457+
Fantom.runTask(() => {
458+
root.render(
459+
<Image
460+
srcSet={
461+
'https://reactnative.dev/img/tiny_logo.png, https://reactnative.dev/img/header_logo.svg 2x'
462+
}
463+
/>,
464+
);
465+
});
466+
467+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
468+
<rn-image
469+
source-1x-scale="1"
470+
source-1x-type="remote"
471+
source-1x-uri="https://reactnative.dev/img/tiny_logo.png"
472+
source-2x-scale="2"
473+
source-2x-type="remote"
474+
source-2x-uri="https://reactnative.dev/img/header_logo.svg"
475+
/>,
476+
);
477+
});
478+
479+
it('uses `src` for `1x` descriptor when provided', () => {
480+
const root = Fantom.createRoot();
481+
482+
Fantom.runTask(() => {
483+
root.render(
484+
<Image
485+
srcSet={
486+
'https://reactnative.dev/img/header_logo.svg 2x, https://reactnative.dev/img/large_logo.svg 3x'
487+
}
488+
src="https://reactnative.dev/img/tiny_logo.png"
489+
/>,
490+
);
491+
});
492+
493+
expect(root.getRenderedOutput({props: ['source']}).toJSX()).toEqual(
494+
<rn-image
495+
source-1x-scale="1"
496+
source-1x-type="remote"
497+
source-1x-uri="https://reactnative.dev/img/tiny_logo.png"
498+
source-2x-scale="2"
499+
source-2x-type="remote"
500+
source-2x-uri="https://reactnative.dev/img/header_logo.svg"
501+
source-3x-type="remote"
502+
source-3x-uri="https://reactnative.dev/img/large_logo.svg"
503+
/>,
504+
);
505+
});
506+
});
386507
});
387508

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

0 commit comments

Comments
 (0)