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 11, 2020
1 parent 9fabfc2 commit 8bac857
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions jest/jestSetup.js
Expand Up @@ -23,16 +23,28 @@ import mockAsyncStorage from '@react-native-community/async-storage/jest/async-s
//
// [1] https://github.com/facebook/react-native/issues/26579#issuecomment-535244001
// [2] https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/.23M3781.20RN.20v0.2E61.20upgrade/near/931219
jest.mock('react-native', () => {
Object.assign(ReactNative.Linking, {
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
openURL: jest.fn(),
canOpenURL: jest.fn(),
getInitialURL: jest.fn(),
});
return ReactNative;
});
jest.mock(
'react-native',
() =>
// Add stuff here
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);

Expand Down

0 comments on commit 8bac857

Please sign in to comment.