Skip to content

Commit 947f5cd

Browse files
mdjastrzebskimeta-codesync[bot]
authored andcommitted
Fix Image Jest mock after extraction to separate package (#55710)
Summary: Transition to `react-native/jest-preset` broke the `Image` mock, as it started to render unmocked `RCTImageView` instead of mocked `Image`. This is result of differences between node resolution that takes into account platform-specific imports (`Image.ios.js`) vs Jest mocking `Image.js`. This works fine in the files are in the same package, but broke when doing deep imports from separate package. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [INTERNAL] [FIXED] Fix `Image` Jest mock after extraction to `react-native/jest-preset` Pull Request resolved: #55710 Test Plan: Added automated tests to showcase the issue Reviewed By: cortinico Differential Revision: D94508659 Pulled By: huntie fbshipit-source-id: a7576e86ad188c917dfc2d2371b609e5b6a02a28
1 parent 34779df commit 947f5cd

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

packages/jest-preset/jest-preset.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010

1111
'use strict';
1212

13+
const path = require('path');
14+
1315
module.exports = {
1416
haste: {
1517
defaultPlatform: 'ios',
1618
platforms: ['android', 'ios', 'native'],
1719
},
20+
moduleNameMapper: {
21+
'^react-native($|/.*)': `${path.dirname(require.resolve('react-native'))}/$1`,
22+
},
1823
resolver: require.resolve('./jest/resolver.js'),
1924
transform: {
2025
'^.+\\.(js|ts|tsx)$': 'babel-jest',

0 commit comments

Comments
 (0)