Skip to content

Commit

Permalink
jest: Use jest-expo as our preset.
Browse files Browse the repository at this point in the history
This calls `react-native`'s Jest setup code before running its own.
In particular, it seems to be aware of all the Expo modules we might
want to add using `react-native-unimodules`, and mocks them [1].
Since we don't need our own mocks for these, remove them.

It seems like we still need to add entries in our
`transformModulesWhitelist`, ah, well. But it's good to weed out
boring mocks from our `jestSetup.js`, and leave only those that are
interesting [2]. Also, it seems like each time we add a module from
Expo, there's a debugging process that can be confusing [3]; so,
nice to avoid that.

It looks like the preset does explicitly consider the bare,
non-"managed" Expo workflow [4], which we use.

If `jest-expo` turns out to be buggy, or the dependency requirements
get even more tangled or burdensome, we should feel free to abandon
this effort; it's not terrible to have to add boring mocks.

[1]: https://github.com/expo/expo/blob/b8bd30697/packages/jest-expo/src/preset/expoModules.js
[2]: Seems like a few remain that aren't related to Expo. Hmm.
[3]: https://github.com/zulip/zulip-mobile/pull/4034/files#r445956933
[4]: https://github.com/expo/expo/blob/b8bd30697/packages/jest-expo/src/preset/setup.js#L130
  • Loading branch information
chrisbobbe committed Jul 11, 2020
1 parent fdb0fc6 commit 9fabfc2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// These will be used as regexp fragments.
const transformModulesWhitelist = [
'expo-apple-authentication',
'expo-application',
'react-native',
// @rnc/async-storage itself is precompiled, but its mock-helper is not
'@react-native-community/async-storage',
Expand All @@ -24,7 +25,7 @@ const transformModulesWhitelist = [
const transformIgnorePattern = `node_modules/(?!${transformModulesWhitelist.join('|')})`;

module.exports = {
preset: 'react-native',
preset: 'jest-expo',

// Finding and transforming source code.

Expand Down
11 changes: 0 additions & 11 deletions jest/jestSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,7 @@ jest.mock('react-native-simple-toast', () => ({
showWithGravity: jest.fn(),
}));

jest.mock('expo-application', () => ({
nativeApplicationVersion: '26.23.146',
}));

jest.mock('react-native-device-info', () => ({
getSystemName: jest.fn().mockReturnValue('ios'),
getSystemVersion: jest.fn().mockReturnValue('13.3.1'),
}));

jest.mock('expo-apple-authentication', () => ({
AppleAuthenticationButton: jest.fn(),
isAvailableAsync: jest.fn(),
signInAsync: jest.fn(),
// etc. (incomplete)
}));

0 comments on commit 9fabfc2

Please sign in to comment.