diff --git a/packages/jest-expo/CHANGELOG.md b/packages/jest-expo/CHANGELOG.md index 27603aa9fccac5..054af3fa178c7e 100644 --- a/packages/jest-expo/CHANGELOG.md +++ b/packages/jest-expo/CHANGELOG.md @@ -13,6 +13,7 @@ - Mock `EventEmitter` from `expo-modules-core`. ([#26945](https://github.com/expo/expo/pull/26945) by [@aleqsio](https://github.com/aleqsio)) - Remove most of Constants.appOwnership. ([#26313](https://github.com/expo/expo/pull/26313) by [@wschurman](https://github.com/wschurman)) - Simulate the mocked `expo-modules-core.EventEmitter` like a true EventEmitter. ([#27257](https://github.com/expo/expo/pull/27257) by [@kudo](https://github.com/kudo)) +- Add mock for `window.__REACT_DEVTOOLS_GLOBAL_HOOK__` if undefined. ([#27434](https://github.com/expo/expo/pull/27434) by [@marklawlor](https://github.com/marklawlor)) ## 50.0.2 - 2024-02-06 diff --git a/packages/jest-expo/src/preset/setup.js b/packages/jest-expo/src/preset/setup.js index eac77843dd1fa9..b93cf333cc49ff 100644 --- a/packages/jest-expo/src/preset/setup.js +++ b/packages/jest-expo/src/preset/setup.js @@ -18,6 +18,21 @@ if (typeof window !== 'object') { globalThis.window.navigator = {}; } +if (typeof globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') { + // RN 0.74 checks for the __REACT_DEVTOOLS_GLOBAL_HOOK__ on startup if getInspectorDataForViewAtPoint is used + // React Navigation uses getInspectorDataForViewAtPoint() for improved log box integration in non-production builds + globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__ = { + isDisabled: true, // Used by `react-test-renderer` https://github.com/facebook/react/blob/113ab9af08c46e8a548a397154f5c9dfeb96ab6a/packages/react-reconciler/src/ReactFiberDevToolsHook.js#L60 + renderers: { + // https://github.com/facebook/react-native/blob/fbbb4246707d85b692c006e0cb3b186a7c9068bc/packages/react-native/Libraries/Inspector/getInspectorDataForViewAtPoint.js#L40 + values: () => [], + }, + on() {}, // https://github.com/facebook/react-native/blob/fbbb4246707d85b692c006e0cb3b186a7c9068bc/packages/react-native/Libraries/Inspector/getInspectorDataForViewAtPoint.js#L45 + }; + // React is inconsistent with how it checks for the global hook + globalThis.window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__; +} + const mockImageLoader = { configurable: true, enumerable: true,