Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jest: Mock "Linking" from
react-native
properly.
With something called Haste, we were allowed to just pass "Linking" to `jest.mock`, and it would automagically be known that we want something called "Linking" from React Native. With RN v0.61, Haste is no longer used, and that way of mocking breaks. One possible response is to spell out the entire path to "Linking" within `react-native`: jest.mock('react-native/Libraries/Linking/Linking') . But that's brittle: that path may change with new React Native versions, and it'll be unpleasant to have to adapt. The recommended solution [1] is to mock the `react-native` module ourselves, on top of the mocking that React Native's Jest setup does for us. And to put our "Linking" mock there. So, do. The *exact* recommendation is something that uses `Object.setPrototypeOf`. We don't do that. Instead, Greg found an earlier revision of the comment where that recommendation appears, and go from there. This way, we avoid an awkward problem with `react-native-vector-icons`. That library re-exports `react-native` in its `lib/react-native.js`, and imports that when they want properties from the `react-native` module. Errors ensue; it appears that their strategy cuts off access to properties we'd intended to make available by using ReactNative as a prototype. So, don't mess around with prototypes. [1] facebook/react-native#26579 (comment)
- Loading branch information