Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.

Commit a4db523

Browse files
jeffreyffsbcarroll22
authored andcommitted
fix: add compatibility for latest versions of React Native
Closes #48
1 parent 840fc0a commit a4db523

File tree

3 files changed

+41
-37
lines changed

3 files changed

+41
-37
lines changed

examples/__tests__/react-navigation.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ import { createStackNavigator, createAppContainer, withNavigation } from 'react-
55

66
import { render, fireEvent } from '../../src';
77

8-
jest.mock('NativeAnimatedHelper').mock('react-native-gesture-handler', () => {
9-
const View = require('react-native').View;
10-
return {
11-
State: {},
12-
PanGestureHandler: View,
13-
BaseButton: View,
14-
Directions: {},
15-
};
16-
});
8+
jest
9+
.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper')
10+
.mock('react-native-gesture-handler', () => {
11+
const View = require('react-native').View;
12+
return {
13+
State: {},
14+
PanGestureHandler: View,
15+
BaseButton: View,
16+
Directions: {},
17+
};
18+
});
1719

1820
const Home = ({ navigation }) => (
1921
<View>

src/preset/configure.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ configureNTL({
1616

1717
// Query lists
1818
coreComponents: [
19-
'ActivityIndicator',
20-
'Button',
21-
'DrawerLayoutAndroid',
22-
'Image',
23-
'Modal',
24-
'Picker',
25-
'RefreshControl',
26-
'SafeAreaView',
27-
'ScrollView',
28-
'Switch',
29-
'Text',
30-
'TextInput',
31-
'TouchableHighlight',
32-
'TouchableNativeFeedback',
33-
'TouchableOpacity',
34-
'TouchableWithoutFeedback',
35-
'View',
19+
'react-native/Libraries/Components/ActivityIndicator/ActivityIndicator',
20+
'react-native/Libraries/Components/Button',
21+
'react-native/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid',
22+
'react-native/Libraries/Image/Image',
23+
'react-native/Libraries/Modal/Modal',
24+
'react-native/Libraries/Components/Picker/Picker',
25+
'react-native/Libraries/Components/RefreshControl/RefreshControl',
26+
'react-native/Libraries/Components/SafeAreaView/SafeAreaView',
27+
'react-native/Libraries/Components/ScrollView/ScrollView',
28+
'react-native/Libraries/Components/Switch/Switch',
29+
'react-native/Libraries/Text/Text',
30+
'react-native/Libraries/Components/TextInput/TextInput',
31+
'react-native/Libraries/Components/Touchable/TouchableHighlight',
32+
'react-native/Libraries/Components/Touchable/TouchableNativeFeedback',
33+
'react-native/Libraries/Components/Touchable/TouchableOpacity',
34+
'react-native/Libraries/Components/Touchable/TouchableWithoutFeedback',
35+
'react-native/Libraries/Components/View/View',
3636
],
3737
displayValueComponents: ['TextInput', 'Picker', 'Switch'],
3838
textComponents: ['Button', 'Text', 'TextInput'],

src/preset/mock-modules.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ getConfig('coreComponents').forEach(component => {
1313
});
1414

1515
// Un-mock ReactNative so we can hide annoying `console.warn`s
16-
jest.unmock('ReactNative');
16+
jest.unmock('react-native/Libraries/Renderer/shims/ReactNative');
1717

1818
// Mock the components we want mocked
1919
getConfig('coreComponents').forEach(component => {
@@ -23,21 +23,23 @@ getConfig('coreComponents').forEach(component => {
2323
});
2424

2525
// Mock the Picker one-off because it's kinda weird
26-
jest.doMock('Picker', () => {
26+
jest.doMock('react-native/Libraries/Components/Picker/Picker', () => {
2727
const React = jest.requireActual('react');
28-
const Picker = mockComponent('Picker');
28+
const Picker = mockComponent('react-native/Libraries/Components/Picker/Picker');
2929
Picker.Item = ({ children, ...props }) => React.createElement('Picker.Item', props, children);
3030
return Picker;
3131
});
3232

3333
// Re-mock ReactNative with native methods mocked
34-
jest.mock('NativeAnimatedHelper').doMock('ReactNative', () => {
35-
const ReactNative = jest.requireActual('ReactNative');
36-
const NativeMethodsMixin =
37-
ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.NativeMethodsMixin;
34+
jest
35+
.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper')
36+
.doMock('react-native/Libraries/Renderer/shims/ReactNative', () => {
37+
const ReactNative = jest.requireActual('react-native/Libraries/Renderer/shims/ReactNative');
38+
const NativeMethodsMixin =
39+
ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.NativeMethodsMixin;
3840

39-
Object.assign(NativeMethodsMixin, mockNativeMethods);
40-
Object.assign(ReactNative.NativeComponent.prototype, mockNativeMethods);
41+
Object.assign(NativeMethodsMixin, mockNativeMethods);
42+
Object.assign(ReactNative.NativeComponent.prototype, mockNativeMethods);
4143

42-
return ReactNative;
43-
});
44+
return ReactNative;
45+
});

0 commit comments

Comments
 (0)