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

Remove dependencies on Haste modules #53

Merged
merged 2 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions examples/__tests__/react-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import { createStackNavigator, createAppContainer, withNavigation } from 'react-

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

jest.mock('NativeAnimatedHelper').mock('react-native-gesture-handler', () => {
const View = require('react-native').View;
return {
State: {},
PanGestureHandler: View,
BaseButton: View,
Directions: {},
};
});
jest
.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper')
.mock('react-native-gesture-handler', () => {
const View = require('react-native').View;
return {
State: {},
PanGestureHandler: View,
BaseButton: View,
Directions: {},
};
});

const Home = ({ navigation }) => (
<View>
Expand Down
34 changes: 17 additions & 17 deletions src/preset/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ configureNTL({

// Query lists
coreComponents: [
'ActivityIndicator',
'Button',
'DrawerLayoutAndroid',
'Image',
'Modal',
'Picker',
'RefreshControl',
'SafeAreaView',
'ScrollView',
'Switch',
'Text',
'TextInput',
'TouchableHighlight',
'TouchableNativeFeedback',
'TouchableOpacity',
'TouchableWithoutFeedback',
'View',
'react-native/Libraries/Components/ActivityIndicator/ActivityIndicator',
'react-native/Libraries/Components/Button',
'react-native/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid',
'react-native/Libraries/Image/Image',
'react-native/Libraries/Modal/Modal',
'react-native/Libraries/Components/Picker/Picker',
'react-native/Libraries/Components/RefreshControl/RefreshControl',
'react-native/Libraries/Components/SafeAreaView/SafeAreaView',
'react-native/Libraries/Components/ScrollView/ScrollView',
'react-native/Libraries/Components/Switch/Switch',
'react-native/Libraries/Text/Text',
'react-native/Libraries/Components/TextInput/TextInput',
'react-native/Libraries/Components/Touchable/TouchableHighlight',
'react-native/Libraries/Components/Touchable/TouchableNativeFeedback',
'react-native/Libraries/Components/Touchable/TouchableOpacity',
'react-native/Libraries/Components/Touchable/TouchableWithoutFeedback',
'react-native/Libraries/Components/View/View',
],
displayValueComponents: ['TextInput', 'Picker', 'Switch'],
textComponents: ['Button', 'Text', 'TextInput'],
Expand Down
24 changes: 13 additions & 11 deletions src/preset/mock-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ getConfig('coreComponents').forEach(component => {
});

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

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

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

// Re-mock ReactNative with native methods mocked
jest.mock('NativeAnimatedHelper').doMock('ReactNative', () => {
const ReactNative = jest.requireActual('ReactNative');
const NativeMethodsMixin =
ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.NativeMethodsMixin;
jest
.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper')
.doMock('react-native/Libraries/Renderer/shims/ReactNative', () => {
const ReactNative = jest.requireActual('react-native/Libraries/Renderer/shims/ReactNative');
const NativeMethodsMixin =
ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.NativeMethodsMixin;

Object.assign(NativeMethodsMixin, mockNativeMethods);
Object.assign(ReactNative.NativeComponent.prototype, mockNativeMethods);
Object.assign(NativeMethodsMixin, mockNativeMethods);
Object.assign(ReactNative.NativeComponent.prototype, mockNativeMethods);

return ReactNative;
});
return ReactNative;
});