Skip to content

Commit

Permalink
ios deps: Mock react-native-device-info.
Browse files Browse the repository at this point in the history
An odd-looking conditional was introduced in 9d9720c; from
experimentation, it looks like this was to prevent some failures
while running our Jest test suite. Some items in NativeModules from
react-native aren't present when Jest is running, so we get errors
if, on startup, we try to run functions that depend on them being
present.

The solution, as we've done for several others, including
`expo-application`, in the parent, is to mock the JS modules that
provide these functions.
  • Loading branch information
Chris Bobbe authored and gnprice committed Apr 8, 2020
1 parent 18c37ce commit 8300c9f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 5 additions & 0 deletions jest/jestSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ jest.mock('react-native-simple-toast', () => ({
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'),
}));
6 changes: 2 additions & 4 deletions src/utils/userAgent.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* @flow strict-local */
import { NativeModules } from 'react-native';
import DeviceInfo from 'react-native-device-info';
import { nativeApplicationVersion } from 'expo-application';

const { getSystemName, getSystemVersion } = DeviceInfo;

export default !NativeModules.RNDeviceInfo
? ''
: `ZulipMobile/${nativeApplicationVersion ?? '?.?.?'} (${getSystemName()} ${getSystemVersion()})`;
export default `ZulipMobile/${nativeApplicationVersion
?? '?.?.?'} (${getSystemName()} ${getSystemVersion()})`;

0 comments on commit 8300c9f

Please sign in to comment.