fix(jest): avoid loading native runtime in mock - #760
Open
huytdps13400 wants to merge 1 commit into
Open
Conversation
Author
|
Added an exact-version consumer verification beyond the repository suite:
Result: Jest passed ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The built-in Jest mock eagerly called
jest.requireActual("react-native-safe-area-context"). Importing the mock therefore evaluated the package runtime and itsStyleSheet/Dimensionsdependencies, which reachesNativeDeviceInfo.getConstants()and fails in affected React Native 0.76 Jest environments.This replaces the eager actual-package dependency with React-only mock contexts, hooks, provider, view, listener, and HOC implementations. The mock keeps the package's 13 runtime exports, preserves custom
initialMetrics, forwardsSafeAreaViewprops/ref to a test host component, and maps listener inset events without loading native code.Fixes #550
Test Plan
src/jest/mockwhile thereact-nativeruntime throws failed atjest.requireActual -> SafeAreaContext -> react-nativebefore the fixyarn validate:jest --runInBand— 6 suites, 26 tests, 11 snapshots passedyarn validate:typescriptyarn validate:eslint— no errors; 3 unchanged deep-import warnings outside this diffyarn format:prettier:checkyarn prepare— CommonJS, ESM, and TypeScript declaration builds passed