From adbd1a7a1509508b9b38a39aebce1c1653556f40 Mon Sep 17 00:00:00 2001 From: Chris Bobbe Date: Wed, 8 Jul 2020 16:28:23 -0700 Subject: [PATCH] jest: Mock "Linking" the right way. 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 https://github.com/facebook/react-native/issues/26579#issuecomment-535244001. --- jest/jestSetup.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/jest/jestSetup.js b/jest/jestSetup.js index c741f13ed23..7c93d682ea0 100644 --- a/jest/jestSetup.js +++ b/jest/jestSetup.js @@ -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, ), @@ -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: () => {}, }));