Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/image methods mock in jest setup (#43497)
Summary: ### Context - Since RN 0.73, in the jest.setup file, methods of the Image module (Image.getSize, Image.resolveAssetSource...) are mocked on the **JS side** (introduced in #36996) - It causes issues like #41907 : `Image.resolveAssetSource` returns nothing in test env with the new JS mock, when some test relies on it. - On my project, it broke the snapshots : the URL of images disappeared. I use `react-native-fast-image` which uses `Image.resolveAssetSource` to compute URLs. - I first opened a PR to fix exclusively Image.resolveAssetSource: #41957. I will close it to focus on this new one. - As suggested by ryancat and idrissakhi, it should be better to return to the previous mock, where no method is mocked on the JS side, and we can trust the actual JS to work in test. This is what this PR intends to do. ### Content Along fixing the Image module mock in jest.setup, this PR : - adds unit test on each one of the methods, ensuring they have a consistent behavior even when the module is mocked. - adds 3 missing native mocks for `NativeImageLoader`: `prefetchImageWithMetadata`, `getSizeWithHeaders` & `queryCache`. After this PR, no method from NativeImageLoader remains unmocked. ## Changelog: [GENERAL][FIXED] - fix jest setup for Image methods (resolveAssetSource, getSize, prefetch, queryCache) Pull Request resolved: #43497 Test Plan: See exhaustive unit tests in PR. You can re-use the mock with all the methods mocked and see how the new unit tests fail. I also patched those changes on my project: my snapshot did have their URL back (see demonstrative screenshots in my original PR: #41957 - NB; fixed mock was different but result was the same -> those screenshots cover only two cases, but anyway they illustrate well the case!) Reviewed By: ryancat Differential Revision: D54959063 Pulled By: tdn120 fbshipit-source-id: 837266bd6991eb8292d9f6af1774e897ac7a8890
- Loading branch information