Closed idrissakhi closed 7 months ago
:warning: | Missing Reproducible Example |
---|---|
:information_source: | We could not detect a reproducible example in your issue report. Please provide either:
|
@idrissakhi could you add a repro?
I have the same using react-native-fast-image, which is also using resolveAssetSource
to get the image sources. My snapshots break with empty URI for all images.
It's because in 0.73 this function resolveAssetSource
is mocked with empty return :
// in packages/react-native/jest/setup.js
.mock('../Libraries/Image/Image', () => {
const Image = mockComponent('../Libraries/Image/Image');
Image.getSize = jest.fn();
Image.getSizeWithHeaders = jest.fn();
Image.prefetch = jest.fn();
Image.prefetchWithMetadata = jest.fn();
Image.queryCache = jest.fn();
Image.resolveAssetSource = jest.fn(); ⬅️⬅️⬅️ 🐞🐞🐞
return Image;
})
A quick fix could be:
Image.resolveAssetSource = jest.fn().mockImplementation(source => source);
New image mock was introduced in 0.73, before we only had :
.mock('../Libraries/Image/Image', () => mockComponent('../Libraries/Image/Image'))
This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.
This issue was closed because the author hasn't provided the requested feedback after 7 days.
Do we have a plan to delegate this fix to 0.73.x, I still got a same error
seems still present in 0.74.3 and 0.74.5. Only 0.74.4 works for me. What is going on?
@JacobDel yes, the fix will be present in the 0.75 only (see https://github.com/facebook/react-native/commit/d53cc2b46dee5ed4d93ee76dea4aea9da42d0158)
You can use this patch like - cc @ducminhleeh:
diff --git a/node_modules/react-native/jest/setup.js b/node_modules/react-native/jest/setup.js
index e98550f..a829f99 100644
--- a/node_modules/react-native/jest/setup.js
+++ b/node_modules/react-native/jest/setup.js
@@ -109,17 +109,8 @@ jest
Constants: {},
},
}))
- .mock('../Libraries/Image/Image', () => {
- const Image = mockComponent('../Libraries/Image/Image');
- Image.getSize = jest.fn();
- Image.getSizeWithHeaders = jest.fn();
- Image.prefetch = jest.fn();
- Image.prefetchWithMetadata = jest.fn();
- Image.queryCache = jest.fn();
- Image.resolveAssetSource = jest.fn();
-
- return Image;
- })
+ .mock('../Libraries/Image/Image', () => mockComponent('../Libraries/Image/Image'),
+ )
.mock('../Libraries/Text/Text', () =>
mockComponent('../Libraries/Text/Text', MockNativeMethods),
)
It's the one I use on 0.73.7; maybe there is some line number difference in 0.74.X, I hav'nt checked. It should not be hard to adapt, the idea is to replace the Image mock by the default one
Description
Describe the bug
TypeError: Cannot read properties of undefined (reading 'width')Jest
Expected behavior Tests passe on 0.72.X
Steps to Reproduce install react native 0.73.0 and run a test having
Versions
npmPackages: @testing-library/react-native: 12.4.1 => 12.4.1 react: 18.2.0 => 18.2.0 react-native: 0.73.0 => 0.73.0 react-test-renderer: 18.2.0 => 18.2.0
Steps to reproduce
Steps to Reproduce install react native 0.73.0 and run a test having
React Native Version
0.73.0
Affected Platforms
Runtime - iOS
Output of
npx react-native info
Stacktrace or Logs
Reproducer
c
Screenshots and Videos
No response