2016-10-17 15:40:11 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2018-05-11 20:32:37 +00:00
|
|
|
*
|
|
|
|
* @format
|
2016-10-17 15:40:11 +00:00
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
|
2016-10-17 15:40:11 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-05-09 07:47:45 +00:00
|
|
|
const MockNativeMethods = require.requireActual('./MockNativeMethods');
|
2016-10-17 15:40:11 +00:00
|
|
|
const mockComponent = require.requireActual('./mockComponent');
|
|
|
|
|
2017-07-21 16:24:39 +00:00
|
|
|
require.requireActual('../Libraries/polyfills/babelHelpers.js');
|
|
|
|
require.requireActual('../Libraries/polyfills/Object.es7.js');
|
|
|
|
require.requireActual('../Libraries/polyfills/error-guard');
|
2016-10-17 15:40:11 +00:00
|
|
|
|
|
|
|
global.__DEV__ = true;
|
|
|
|
|
|
|
|
global.Promise = require.requireActual('promise');
|
2018-05-11 20:32:37 +00:00
|
|
|
global.regeneratorRuntime = require.requireActual(
|
|
|
|
'regenerator-runtime/runtime',
|
|
|
|
);
|
2016-10-17 15:40:11 +00:00
|
|
|
|
2017-05-05 00:29:09 +00:00
|
|
|
global.requestAnimationFrame = function(callback) {
|
2017-10-14 20:50:56 +00:00
|
|
|
return setTimeout(callback, 0);
|
2017-05-05 00:29:09 +00:00
|
|
|
};
|
|
|
|
global.cancelAnimationFrame = function(id) {
|
|
|
|
clearTimeout(id);
|
|
|
|
};
|
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
jest.mock('setupDevtools').mock('npmlog');
|
2016-10-17 15:40:11 +00:00
|
|
|
|
|
|
|
// there's a __mock__ for it.
|
|
|
|
jest.setMock('ErrorUtils', require('ErrorUtils'));
|
|
|
|
|
|
|
|
jest
|
2017-09-28 01:19:44 +00:00
|
|
|
.mock('InitializeCore', () => {})
|
2016-10-17 15:40:11 +00:00
|
|
|
.mock('Image', () => mockComponent('Image'))
|
2018-05-09 07:47:57 +00:00
|
|
|
.mock('Text', () => mockComponent('Text', MockNativeMethods))
|
2016-10-17 15:40:11 +00:00
|
|
|
.mock('TextInput', () => mockComponent('TextInput'))
|
|
|
|
.mock('Modal', () => mockComponent('Modal'))
|
2018-05-09 07:47:48 +00:00
|
|
|
.mock('View', () => mockComponent('View', MockNativeMethods))
|
2016-12-20 23:44:54 +00:00
|
|
|
.mock('RefreshControl', () => require.requireMock('RefreshControlMock'))
|
|
|
|
.mock('ScrollView', () => require.requireMock('ScrollViewMock'))
|
2018-05-11 20:32:37 +00:00
|
|
|
.mock('ActivityIndicator', () => mockComponent('ActivityIndicator'))
|
2016-12-20 23:44:54 +00:00
|
|
|
.mock('ListView', () => require.requireMock('ListViewMock'))
|
2016-10-17 15:40:11 +00:00
|
|
|
.mock('ListViewDataSource', () => {
|
|
|
|
const DataSource = require.requireActual('ListViewDataSource');
|
|
|
|
DataSource.prototype.toJSON = function() {
|
|
|
|
function ListViewDataSource(dataBlob) {
|
|
|
|
this.items = 0;
|
|
|
|
// Ensure this doesn't throw.
|
|
|
|
try {
|
|
|
|
Object.keys(dataBlob).forEach(key => {
|
2018-05-11 20:32:37 +00:00
|
|
|
this.items +=
|
|
|
|
dataBlob[key] &&
|
|
|
|
(dataBlob[key].length || dataBlob[key].size || 0);
|
2016-10-17 15:40:11 +00:00
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
this.items = 'unknown';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ListViewDataSource(this._dataBlob);
|
|
|
|
};
|
|
|
|
return DataSource;
|
|
|
|
})
|
2017-08-09 19:18:46 +00:00
|
|
|
.mock('AnimatedImplementation', () => {
|
2018-05-11 20:32:37 +00:00
|
|
|
const AnimatedImplementation = require.requireActual(
|
|
|
|
'AnimatedImplementation',
|
|
|
|
);
|
2017-08-09 19:18:46 +00:00
|
|
|
const oldCreate = AnimatedImplementation.createAnimatedComponent;
|
|
|
|
AnimatedImplementation.createAnimatedComponent = function(Component) {
|
|
|
|
const Wrapped = oldCreate(Component);
|
|
|
|
Wrapped.__skipSetNativeProps_FOR_TESTS_ONLY = true;
|
|
|
|
return Wrapped;
|
|
|
|
};
|
|
|
|
return AnimatedImplementation;
|
|
|
|
})
|
|
|
|
.mock('ReactNative', () => {
|
|
|
|
const ReactNative = require.requireActual('ReactNative');
|
|
|
|
const NativeMethodsMixin =
|
2018-05-11 20:32:37 +00:00
|
|
|
ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
|
|
|
|
.NativeMethodsMixin;
|
2018-03-09 21:09:12 +00:00
|
|
|
|
2018-05-09 07:47:45 +00:00
|
|
|
Object.assign(NativeMethodsMixin, MockNativeMethods);
|
|
|
|
Object.assign(ReactNative.NativeComponent.prototype, MockNativeMethods);
|
2018-03-09 21:09:12 +00:00
|
|
|
|
2017-08-09 19:18:46 +00:00
|
|
|
return ReactNative;
|
|
|
|
})
|
2016-10-17 15:40:11 +00:00
|
|
|
.mock('ensureComponentIsNative', () => () => true);
|
|
|
|
|
|
|
|
const mockEmptyObject = {};
|
|
|
|
const mockNativeModules = {
|
|
|
|
AlertManager: {
|
|
|
|
alertWithArgs: jest.fn(),
|
|
|
|
},
|
2016-11-29 22:39:28 +00:00
|
|
|
AppState: {
|
|
|
|
addEventListener: jest.fn(),
|
2018-02-26 05:55:18 +00:00
|
|
|
removeEventListener: jest.fn(),
|
2016-11-29 22:39:28 +00:00
|
|
|
},
|
2016-10-17 15:40:11 +00:00
|
|
|
AsyncLocalStorage: {
|
2018-05-11 20:32:37 +00:00
|
|
|
multiGet: jest.fn((keys, callback) =>
|
|
|
|
process.nextTick(() => callback(null, [])),
|
|
|
|
),
|
|
|
|
multiSet: jest.fn((entries, callback) =>
|
|
|
|
process.nextTick(() => callback(null)),
|
|
|
|
),
|
|
|
|
multiRemove: jest.fn((keys, callback) =>
|
|
|
|
process.nextTick(() => callback(null)),
|
|
|
|
),
|
|
|
|
multiMerge: jest.fn((entries, callback) =>
|
|
|
|
process.nextTick(() => callback(null)),
|
|
|
|
),
|
2017-04-13 13:17:15 +00:00
|
|
|
clear: jest.fn(callback => process.nextTick(() => callback(null))),
|
|
|
|
getAllKeys: jest.fn(callback => process.nextTick(() => callback(null, []))),
|
2016-10-17 15:40:11 +00:00
|
|
|
},
|
|
|
|
BuildInfo: {
|
|
|
|
appVersion: '0',
|
|
|
|
buildVersion: '0',
|
|
|
|
},
|
|
|
|
Clipboard: {
|
|
|
|
setString: jest.fn(),
|
|
|
|
},
|
|
|
|
DataManager: {
|
|
|
|
queryData: jest.fn(),
|
|
|
|
},
|
2017-03-17 23:47:51 +00:00
|
|
|
DeviceInfo: {
|
|
|
|
Dimensions: {
|
|
|
|
window: {
|
|
|
|
fontScale: 2,
|
|
|
|
height: 1334,
|
|
|
|
scale: 2,
|
|
|
|
width: 750,
|
|
|
|
},
|
2017-12-04 00:34:26 +00:00
|
|
|
screen: {
|
|
|
|
fontScale: 2,
|
|
|
|
height: 1334,
|
|
|
|
scale: 2,
|
|
|
|
width: 750,
|
|
|
|
},
|
2017-03-17 23:47:51 +00:00
|
|
|
},
|
|
|
|
},
|
2016-10-17 15:40:11 +00:00
|
|
|
FacebookSDK: {
|
|
|
|
login: jest.fn(),
|
|
|
|
logout: jest.fn(),
|
|
|
|
queryGraphPath: jest.fn((path, method, params, callback) => callback()),
|
|
|
|
},
|
|
|
|
GraphPhotoUpload: {
|
|
|
|
upload: jest.fn(),
|
|
|
|
},
|
|
|
|
I18n: {
|
|
|
|
translationsDictionary: JSON.stringify({
|
|
|
|
'Good bye, {name}!|Bye message': '\u{00A1}Adi\u{00F3}s {name}!',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
ImageLoader: {
|
2018-05-11 20:32:37 +00:00
|
|
|
getSize: jest.fn(url => Promise.resolve({width: 320, height: 240})),
|
2016-10-17 15:40:11 +00:00
|
|
|
prefetchImage: jest.fn(),
|
|
|
|
},
|
|
|
|
ImageViewManager: {
|
2018-05-11 20:32:37 +00:00
|
|
|
getSize: jest.fn((uri, success) =>
|
|
|
|
process.nextTick(() => success(320, 240)),
|
2016-10-17 15:40:11 +00:00
|
|
|
),
|
|
|
|
prefetchImage: jest.fn(),
|
|
|
|
},
|
2016-10-31 19:52:30 +00:00
|
|
|
KeyboardObserver: {
|
|
|
|
addListener: jest.fn(),
|
|
|
|
removeListeners: jest.fn(),
|
|
|
|
},
|
2017-04-19 11:10:37 +00:00
|
|
|
Linking: {
|
|
|
|
openURL: jest.fn(),
|
2018-05-11 20:32:37 +00:00
|
|
|
canOpenURL: jest.fn(() => Promise.resolve(true)),
|
2017-06-29 07:58:52 +00:00
|
|
|
addEventListener: jest.fn(),
|
2018-05-11 20:32:37 +00:00
|
|
|
getInitialURL: jest.fn(() => Promise.resolve()),
|
2017-06-29 07:58:52 +00:00
|
|
|
removeEventListener: jest.fn(),
|
2017-04-19 11:10:37 +00:00
|
|
|
},
|
2017-04-13 16:16:09 +00:00
|
|
|
LocationObserver: {
|
|
|
|
getCurrentPosition: jest.fn(),
|
|
|
|
startObserving: jest.fn(),
|
|
|
|
stopObserving: jest.fn(),
|
|
|
|
},
|
2016-10-17 15:40:11 +00:00
|
|
|
ModalFullscreenViewManager: {},
|
2017-06-29 07:58:52 +00:00
|
|
|
NetInfo: {
|
2018-05-11 20:32:37 +00:00
|
|
|
fetch: jest.fn(() => Promise.resolve()),
|
|
|
|
getConnectionInfo: jest.fn(() => Promise.resolve()),
|
2017-06-29 07:58:52 +00:00
|
|
|
addEventListener: jest.fn(),
|
2017-11-10 17:56:38 +00:00
|
|
|
removeEventListener: jest.fn(),
|
2017-06-29 07:58:52 +00:00
|
|
|
isConnected: {
|
2018-05-11 20:32:37 +00:00
|
|
|
fetch: jest.fn(() => Promise.resolve()),
|
2017-06-29 07:58:52 +00:00
|
|
|
addEventListener: jest.fn(),
|
2017-11-10 17:56:38 +00:00
|
|
|
removeEventListener: jest.fn(),
|
2017-06-29 07:58:52 +00:00
|
|
|
},
|
2018-05-11 20:32:37 +00:00
|
|
|
isConnectionExpensive: jest.fn(() => Promise.resolve()),
|
2017-06-29 07:58:52 +00:00
|
|
|
},
|
2016-10-31 19:52:30 +00:00
|
|
|
Networking: {
|
|
|
|
sendRequest: jest.fn(),
|
|
|
|
abortRequest: jest.fn(),
|
|
|
|
addListener: jest.fn(),
|
|
|
|
removeListeners: jest.fn(),
|
|
|
|
},
|
2017-05-11 10:36:55 +00:00
|
|
|
PushNotificationManager: {
|
|
|
|
presentLocalNotification: jest.fn(),
|
|
|
|
scheduleLocalNotification: jest.fn(),
|
|
|
|
cancelAllLocalNotifications: jest.fn(),
|
|
|
|
removeAllDeliveredNotifications: jest.fn(),
|
|
|
|
getDeliveredNotifications: jest.fn(callback => process.nextTick(() => [])),
|
|
|
|
removeDeliveredNotifications: jest.fn(),
|
|
|
|
setApplicationIconBadgeNumber: jest.fn(),
|
2018-05-11 20:32:37 +00:00
|
|
|
getApplicationIconBadgeNumber: jest.fn(callback =>
|
|
|
|
process.nextTick(() => callback(0)),
|
|
|
|
),
|
2017-05-11 10:36:55 +00:00
|
|
|
cancelLocalNotifications: jest.fn(),
|
2018-05-11 20:32:37 +00:00
|
|
|
getScheduledLocalNotifications: jest.fn(callback =>
|
|
|
|
process.nextTick(() => callback()),
|
|
|
|
),
|
|
|
|
requestPermissions: jest.fn(() =>
|
|
|
|
Promise.resolve({alert: true, badge: true, sound: true}),
|
|
|
|
),
|
2017-05-11 10:36:55 +00:00
|
|
|
abandonPermissions: jest.fn(),
|
2018-05-11 20:32:37 +00:00
|
|
|
checkPermissions: jest.fn(callback =>
|
|
|
|
process.nextTick(() => callback({alert: true, badge: true, sound: true})),
|
|
|
|
),
|
2017-05-11 10:36:55 +00:00
|
|
|
getInitialNotification: jest.fn(() => Promise.resolve(null)),
|
|
|
|
addListener: jest.fn(),
|
|
|
|
removeListeners: jest.fn(),
|
|
|
|
},
|
2016-10-17 15:40:11 +00:00
|
|
|
SourceCode: {
|
|
|
|
scriptURL: null,
|
|
|
|
},
|
2016-12-06 13:43:42 +00:00
|
|
|
StatusBarManager: {
|
2018-05-15 20:38:30 +00:00
|
|
|
HEIGHT: 42,
|
2017-01-21 00:41:24 +00:00
|
|
|
setColor: jest.fn(),
|
2016-12-06 13:43:42 +00:00
|
|
|
setStyle: jest.fn(),
|
|
|
|
setHidden: jest.fn(),
|
|
|
|
setNetworkActivityIndicatorVisible: jest.fn(),
|
|
|
|
setBackgroundColor: jest.fn(),
|
|
|
|
setTranslucent: jest.fn(),
|
|
|
|
},
|
2016-10-17 15:40:11 +00:00
|
|
|
Timing: {
|
|
|
|
createTimer: jest.fn(),
|
|
|
|
deleteTimer: jest.fn(),
|
|
|
|
},
|
|
|
|
UIManager: {
|
2017-05-15 22:44:52 +00:00
|
|
|
AndroidViewPager: {
|
|
|
|
Commands: {
|
|
|
|
setPage: jest.fn(),
|
|
|
|
setPageWithoutAnimation: jest.fn(),
|
|
|
|
},
|
|
|
|
},
|
2017-03-23 04:22:44 +00:00
|
|
|
blur: jest.fn(),
|
2017-01-21 00:41:24 +00:00
|
|
|
createView: jest.fn(),
|
2017-03-23 04:22:44 +00:00
|
|
|
dispatchViewManagerCommand: jest.fn(),
|
|
|
|
focus: jest.fn(),
|
2017-01-21 00:41:24 +00:00
|
|
|
setChildren: jest.fn(),
|
|
|
|
manageChildren: jest.fn(),
|
|
|
|
updateView: jest.fn(),
|
|
|
|
removeSubviewsFromContainerWithID: jest.fn(),
|
|
|
|
replaceExistingNonRootView: jest.fn(),
|
2016-10-17 15:40:11 +00:00
|
|
|
customBubblingEventTypes: {},
|
|
|
|
customDirectEventTypes: {},
|
2017-03-23 04:22:44 +00:00
|
|
|
AndroidTextInput: {
|
|
|
|
Commands: {},
|
|
|
|
},
|
2016-10-28 17:56:58 +00:00
|
|
|
ModalFullscreenView: {
|
2016-10-17 15:40:11 +00:00
|
|
|
Constants: {},
|
|
|
|
},
|
2016-10-28 17:56:58 +00:00
|
|
|
ScrollView: {
|
2016-10-17 15:40:11 +00:00
|
|
|
Constants: {},
|
|
|
|
},
|
2016-10-28 17:56:58 +00:00
|
|
|
View: {
|
2016-10-17 15:40:11 +00:00
|
|
|
Constants: {},
|
|
|
|
},
|
|
|
|
},
|
2017-09-07 06:44:19 +00:00
|
|
|
BlobModule: {
|
|
|
|
BLOB_URI_SCHEME: 'content',
|
|
|
|
BLOB_URI_HOST: null,
|
2018-04-09 18:15:22 +00:00
|
|
|
addNetworkingHandler: jest.fn(),
|
2017-09-07 06:44:19 +00:00
|
|
|
enableBlobSupport: jest.fn(),
|
|
|
|
disableBlobSupport: jest.fn(),
|
|
|
|
createFromParts: jest.fn(),
|
|
|
|
sendBlob: jest.fn(),
|
|
|
|
release: jest.fn(),
|
|
|
|
},
|
2016-10-31 19:52:30 +00:00
|
|
|
WebSocketModule: {
|
|
|
|
connect: jest.fn(),
|
|
|
|
send: jest.fn(),
|
|
|
|
sendBinary: jest.fn(),
|
|
|
|
ping: jest.fn(),
|
|
|
|
close: jest.fn(),
|
|
|
|
addListener: jest.fn(),
|
|
|
|
removeListeners: jest.fn(),
|
|
|
|
},
|
2016-10-17 15:40:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Object.keys(mockNativeModules).forEach(module => {
|
|
|
|
try {
|
|
|
|
jest.doMock(module, () => mockNativeModules[module]); // needed by FacebookSDK-test
|
|
|
|
} catch (e) {
|
|
|
|
jest.doMock(module, () => mockNativeModules[module], {virtual: true});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
jest.doMock('NativeModules', () => mockNativeModules);
|
2016-10-23 03:17:32 +00:00
|
|
|
|
|
|
|
jest.doMock('requireNativeComponent', () => {
|
|
|
|
const React = require('react');
|
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
return viewName =>
|
|
|
|
class extends React.Component {
|
|
|
|
render() {
|
|
|
|
return React.createElement(viewName, this.props, this.props.children);
|
|
|
|
}
|
|
|
|
};
|
2016-10-23 03:17:32 +00:00
|
|
|
});
|