Skip to content

Commit 4a75284

Browse files
chore: update mock
1 parent c010b01 commit 4a75284

File tree

2 files changed

+477
-801
lines changed

2 files changed

+477
-801
lines changed

packages/pluggableWidgets/image-native/src/components/__tests__/Image.spec.tsx

Lines changed: 36 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -36,64 +36,44 @@ jest.mock("react-native/Libraries/Image/Image", () => {
3636
});
3737

3838
jest.mock("@d11/react-native-fast-image", () => {
39-
const { Image } = jest.requireActual("react-native");
40-
41-
const FastImage = (props: any): JSX.Element => {
42-
// Map FastImage props to React Native Image props
43-
const {
44-
source,
45-
resizeMode,
46-
onFastImageLoadStart,
47-
onFastImageProgress,
48-
onFastImageLoad,
49-
onFastImageError,
50-
onFastImageLoadEnd,
51-
...otherProps
52-
} = props;
53-
54-
return (
55-
<Image
56-
{...otherProps}
57-
source={source}
58-
resizeMode={resizeMode}
59-
onLoadStart={onFastImageLoadStart}
60-
onProgress={onFastImageProgress}
61-
onLoad={onFastImageLoad}
62-
onError={onFastImageError}
63-
onLoadEnd={onFastImageLoadEnd}
64-
/>
39+
const React = jest.requireActual("react") as typeof import("react");
40+
// eslint-disable-next-line @typescript-eslint/no-var-requires
41+
const { resolveAssetSource } = require("react-native/Libraries/Image/Image");
42+
const FastImage = ({
43+
testID,
44+
style,
45+
source: originalSource,
46+
resizeMode
47+
}: {
48+
testID: string;
49+
style: any;
50+
source: any;
51+
resizeMode: string;
52+
}): any => {
53+
let source = originalSource;
54+
try {
55+
if (typeof originalSource === "number") {
56+
const asset = resolveAssetSource(originalSource);
57+
source = asset ? { height: asset.height, width: asset.width } : { height: 0, width: 0 };
58+
} else if (originalSource?.uri) {
59+
// Dynamic image: use fixed dimensions to match stored snapshots
60+
source = { height: 1111, width: 2222 };
61+
}
62+
} catch (_) {
63+
source = { height: 0, width: 0 };
64+
}
65+
return React.createElement(
66+
"View",
67+
{ style: [{ overflow: "hidden" }, Array.isArray(style) ? style : [style]] },
68+
React.createElement("FastImageView", {
69+
testID,
70+
style: { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 },
71+
source,
72+
resizeMode
73+
})
6574
);
6675
};
67-
68-
// Add static properties that FastImage has
69-
FastImage.resizeMode = {
70-
contain: "contain",
71-
cover: "cover",
72-
stretch: "stretch",
73-
center: "center"
74-
};
75-
76-
FastImage.priority = {
77-
low: "low",
78-
normal: "normal",
79-
high: "high"
80-
};
81-
82-
FastImage.cacheControl = {
83-
immutable: "immutable",
84-
web: "web",
85-
cacheOnly: "cacheOnly"
86-
};
87-
88-
FastImage.preload = jest.fn();
89-
FastImage.clearMemoryCache = jest.fn(() => Promise.resolve());
90-
FastImage.clearDiskCache = jest.fn(() => Promise.resolve());
91-
92-
return {
93-
__esModule: true,
94-
default: FastImage,
95-
Source: {} // Type export, empty object for tests
96-
};
76+
return { __esModule: true, default: FastImage };
9777
});
9878

9979
const onLayoutEventData = {

0 commit comments

Comments
 (0)