UNPKG

@d11/react-native-fast-image

Version:
57 lines (56 loc) • 2.8 kB
import { StyleSheet, Platform, NativeModules } from 'react-native'; import React from 'react'; import { render } from '@testing-library/react-native'; import FastImage from './index'; const style = StyleSheet.create({ image: { width: 44, height: 44 } }); describe('FastImage (iOS)', () => { beforeAll(() => { Platform.OS = 'ios'; NativeModules.FastImageView = { preload: Function.prototype, clearMemoryCache: Function.prototype, clearDiskCache: Function.prototype, }; }); it('renders', () => { const { toJSON } = render(React.createElement(FastImage, { source: { uri: 'https://facebook.github.io/react/img/logo_og.png', headers: { token: 'someToken', }, priority: FastImage.priority.high, }, style: style.image })); expect(toJSON()).toMatchSnapshot(); }); it('renders a normal Image when not passed a uri', () => { const { toJSON } = render(React.createElement(FastImage, { source: require('../ReactNativeFastImageExampleServer/pictures/jellyfish.gif'), style: style.image })); expect(toJSON()).toMatchSnapshot(); }); it('renders Image with fallback prop', () => { const { toJSON } = render(React.createElement(FastImage, { source: require('../ReactNativeFastImageExampleServer/pictures/jellyfish.gif'), style: style.image, fallback: true })); expect(toJSON()).toMatchSnapshot(); }); it('renders defaultSource', () => { const { toJSON } = render(React.createElement(FastImage, { defaultSource: require('../ReactNativeFastImageExampleServer/pictures/jellyfish.gif'), style: style.image })); expect(toJSON()).toMatchSnapshot(); }); }); describe('FastImage (Android)', () => { beforeAll(() => { Platform.OS = 'android'; }); it('renders a normal defaultSource', () => { const { toJSON } = render(React.createElement(FastImage, { defaultSource: require('../ReactNativeFastImageExampleServer/pictures/jellyfish.gif'), style: style.image })); expect(toJSON()).toMatchSnapshot(); }); it('renders a normal defaultSource when fails to load source', () => { const { toJSON } = render(React.createElement(FastImage, { defaultSource: require('../ReactNativeFastImageExampleServer/pictures/jellyfish.gif'), source: { uri: 'https://www.google.com/image_does_not_exist.png', }, style: style.image })); expect(toJSON()).toMatchSnapshot(); }); it('renders a non-existing defaultSource', () => { const { toJSON } = render(React.createElement(FastImage, { defaultSource: 12345, style: style.image })); expect(toJSON()).toMatchSnapshot(); }); });