โก๏ธ Unstable Rendering
Stability Issuesโ
Some components may render differently between test runs due to:
- Moving Elements - animations, videos
- Network Images - external URL images
- Dynamic Data - API data, timestamps
Moving Elementsโ
Components with animations and videos can cause inconsistent screenshots between test runs
Solution - Static Elements
import { isRunningVisualTests } from "@sherlo/react-native-storybook";
function MovingComponent() {
return (
<>
{/* โ Animated - unreliable */}
<Loader animated={true} />
{/* โ
Disabled animation in tests */}
<Loader animated={!isRunningVisualTests} />
{/* โ Playing video - unreliable */}
<Video />
{/* โ
Paused video in tests */}
<Video paused={isRunningVisualTests} />
</>
);
}
Network Imagesโ
Network-loaded images may fail or differ due to timeouts, server overload, or CDN issues
Solution - Local Images
import { isRunningVisualTests } from "@sherlo/react-native-storybook";
function ImageComponent() {
return (
<>
{/* โ Network image - unreliable */}
<Image source={{ uri: "https://example.com/image.jpg" }} />
{/* โ
Local image */}
<Image source={require("../assets/image.jpg")} />
{/* โ
Local image as URI */}
<Image
source={{
uri: Image.resolveAssetSource(require("../assets/image.jpg")).uri
}}
/>
{/* โ
Local image in tests */}
<Image
source={isRunningVisualTests
? require("../assets/image.jpg")
: { uri: "https://example.com/image.jpg" }
}
/>
</>
);
}
Dynamic Dataโ
Real-time data like API responses and timestamps change between test runs, causing visual differences
Solution - Static Data
import { isRunningVisualTests } from "@sherlo/react-native-storybook";
function DataComponent() {
return (
<>
{/* โ Live API data - unreliable */}
<Text>Price: {getPrice()}</Text>
{/* โ
Mocked API data in tests */}
<Text>
Price: {isRunningVisualTests ? "$4.20" : getPrice()}
</Text>
{/* โ Live timestamp - unreliable */}
<Text>{new Date().toLocaleString()}</Text>
{/* โ
Static timestamp in tests */}
<Text>
{isRunningVisualTests
? "Apr 2, 2005 9:37 PM"
: new Date().toLocaleString()
}
</Text>
</>
);
}