diff --git a/jest/jestSetup.js b/jest/jestSetup.js index fe24d893c58..94cf0f9b53f 100644 --- a/jest/jestSetup.js +++ b/jest/jestSetup.js @@ -25,9 +25,9 @@ jest.mock('react-native', () => // Extend ReactNative Object.setPrototypeOf( { - // Adding something directly from RN here, as in - // `Foo: ReactNative.Foo`, is not done because we want to mock - // Foo ourselves. + // Boring RN mocks. Adding something directly from RN here, as + // in `Foo: ReactNative.Foo`, is not done because we want to + // mock Foo ourselves. // // One reason to have to do this is because of an odd // indirection in `react-native-vector-icons`. They re-export @@ -43,19 +43,27 @@ 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, ), ); +/** + * Boring mocks + * + * We aren't interested in any specific data in these mocks; they just + * make things not break. Usually it's because these JS modules depend + * on something being available on NativeModules, and we'd rather not + * mock that precisely, as it's an implementation detail that may + * change. + * + * If Jest complains about syntax errors in a module in node_modules, + * it's likely because the only code it finds for the module is modern + * JavaScript that needs to be transformed by Babel. In that case, try + * adding the module to `transformModulesWhitelist` in our Jest config + * before mocking it here. + */ + jest.mock('@react-native-community/async-storage', () => mockAsyncStorage); jest.mock('react-native-sound', () => () => ({