Skip to content

Commit

Permalink
jest: Mock "Linking" the right way.
Browse files Browse the repository at this point in the history
In the upcoming RN v0.60 -> v0.61 upgrade, Haste won't be used, so
the string "Linking" won't be resolved.

Move our "Linking" mock into our mock of 'react-native', added
in a recent commit, rather than pointing to
'react-native/Libraries/Linking/Linking' and thus coupling our tests
with the internal directory structure of `react-native`. [1]

[1]: See React Native's recommendation of this strategy, at
     facebook/react-native#26579 (comment).
  • Loading branch information
chrisbobbe committed Jul 10, 2020
1 parent e52bb79 commit adbd1a7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions jest/jestSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ jest.mock('react-native', () =>
Platform: ReactNative.Platform,
StyleSheet: ReactNative.StyleSheet,
NativeModules: ReactNative.NativeModules,

Linking: {
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
openURL: jest.fn(),
canOpenURL: jest.fn(),
getInitialURL: jest.fn(),
},
},
ReactNative,
),
Expand All @@ -54,14 +62,6 @@ jest.mock('react-native-sound', () => () => ({
play: jest.fn(),
}));

jest.mock('Linking', () => ({
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
openURL: jest.fn(),
canOpenURL: jest.fn(),
getInitialURL: jest.fn(),
}));

jest.mock('rn-fetch-blob', () => ({
DocumentDir: () => {},
}));
Expand Down

0 comments on commit adbd1a7

Please sign in to comment.