Skip to content

Commit

Permalink
jest: Comment about boring mocks, remove one that's unnecessary.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
chrisbobbe committed Jul 9, 2020
1 parent 379d386 commit 9bb1c4d
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions jest/jestSetup.js
Expand Up @@ -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
Expand All @@ -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', () => () => ({
Expand Down

0 comments on commit 9bb1c4d

Please sign in to comment.