From 9bb1c4d002ba38a8f4d42f0e5eb950aa506d47fe Mon Sep 17 00:00:00 2001 From: Chris Bobbe Date: Thu, 9 Jul 2020 12:26:17 -0700 Subject: [PATCH] jest: Comment about boring mocks, remove one that's unnecessary. I'm not sure when exactly it became unnecessary to mock "Linking", but it's taken care of now in React Native's Jest setup [1]. [1]: https://github.com/facebook/react-native/blob/v0.61.5/jest/setup.js#L153 --- jest/jestSetup.js | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) 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', () => () => ({