2016-10-17 15:40:11 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
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');
|
2017-07-13 02:22:43 +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) {
|
|
|
|
setTimeout(callback, 0);
|
|
|
|
};
|
|
|
|
global.cancelAnimationFrame = function(id) {
|
|
|
|
clearTimeout(id);
|
|
|
|
};
|
|
|
|
|
2017-07-13 02:22:43 +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-02-08 22:38:37 +00:00
|
|
|
.mock('InitializeCore')
|
2016-10-17 15:40:11 +00:00
|
|
|
.mock('Image', () => mockComponent('Image'))
|
|
|
|
.mock('Text', () => mockComponent('Text'))
|
|
|
|
.mock('TextInput', () => mockComponent('TextInput'))
|
|
|
|
.mock('Modal', () => mockComponent('Modal'))
|
|
|
|
.mock('View', () => mockComponent('View'))
|
2016-12-20 23:44:54 +00:00
|
|
|
.mock('RefreshControl', () => require.requireMock('RefreshControlMock'))
|
|
|
|
.mock('ScrollView', () => require.requireMock('ScrollViewMock'))
|
2017-07-13 02:22:43 +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 => {
|
2017-07-13 02:22:43 +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', () => {
|
|
|
|
const AnimatedImplementation = require.requireActual('AnimatedImplementation');
|
|
|
|
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 =
|
|
|
|
ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.NativeMethodsMixin;
|
|
|
|
[
|
|
|
|
'measure',
|
|
|
|
'measureInWindow',
|
|
|
|
'measureLayout',
|
|
|
|
'setNativeProps',
|
|
|
|
'focus',
|
|
|
|
'blur',
|
|
|
|
].forEach((key) => {
|
|
|
|
let warned = false;
|
|
|
|
NativeMethodsMixin[key] = function() {
|
|
|
|
if (warned) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
warned = true;
|
|
|
|
console.warn(
|
|
|
|
'Calling .' + key + '() in the test renderer environment is not ' +
|
|
|
|
'supported. Instead, mock out your components that use ' +
|
|
|
|
'findNodeHandle with replacements that don\'t rely on the ' +
|
|
|
|
'native environment.',
|
|
|
|
);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
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(),
|
|
|
|
},
|
2016-10-17 15:40:11 +00:00
|
|
|
AsyncLocalStorage: {
|
2017-07-13 02:22:43 +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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-10-17 15:40:11 +00:00
|
|
|
FacebookSDK: {
|
|
|
|
login: jest.fn(),
|
|
|
|
logout: jest.fn(),
|
|
|
|
queryGraphPath: jest.fn((path, method, params, callback) => callback()),
|
|
|
|
},
|
|
|
|
FbRelayNativeAdapter: {
|
|
|
|
updateCLC: jest.fn(),
|
|
|
|
},
|
|
|
|
GraphPhotoUpload: {
|
|
|
|
upload: jest.fn(),
|
|
|
|
},
|
|
|
|
I18n: {
|
|
|
|
translationsDictionary: JSON.stringify({
|
|
|
|
'Good bye, {name}!|Bye message': '\u{00A1}Adi\u{00F3}s {name}!',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
ImageLoader: {
|
2017-07-13 02:22:43 +00:00
|
|
|
getSize: jest.fn(
|
|
|
|
(url) => new Promise(() => ({width: 320, height: 240}))
|
|
|
|
),
|
2016-10-17 15:40:11 +00:00
|
|
|
prefetchImage: jest.fn(),
|
|
|
|
},
|
|
|
|
ImageViewManager: {
|
2017-07-13 02:22:43 +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(),
|
2017-07-13 02:22:43 +00:00
|
|
|
canOpenURL: jest.fn(
|
|
|
|
() => new Promise((resolve) => resolve(true))
|
|
|
|
),
|
2017-06-29 07:58:52 +00:00
|
|
|
addEventListener: jest.fn(),
|
2017-07-13 02:22:43 +00:00
|
|
|
getInitialURL: jest.fn(
|
|
|
|
() => new Promise((resolve) => 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: {
|
2017-07-13 02:22:43 +00:00
|
|
|
fetch: jest.fn(
|
|
|
|
() => new Promise((resolve) => resolve())
|
|
|
|
),
|
2017-06-29 07:58:52 +00:00
|
|
|
addEventListener: jest.fn(),
|
|
|
|
isConnected: {
|
2017-07-13 02:22:43 +00:00
|
|
|
fetch: jest.fn(
|
|
|
|
() => new Promise((resolve) => resolve())
|
|
|
|
),
|
2017-06-29 07:58:52 +00:00
|
|
|
addEventListener: jest.fn(),
|
|
|
|
},
|
|
|
|
},
|
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(),
|
2017-07-13 02:22:43 +00:00
|
|
|
getApplicationIconBadgeNumber: jest.fn(callback => process.nextTick(() => callback(0))),
|
2017-05-11 10:36:55 +00:00
|
|
|
cancelLocalNotifications: jest.fn(),
|
2017-07-13 02:22:43 +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(),
|
2017-07-13 02:22:43 +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: {
|
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: {},
|
|
|
|
},
|
|
|
|
},
|
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});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
jest
|
|
|
|
.doMock('NativeModules', () => mockNativeModules)
|
|
|
|
.doMock('ReactNativePropRegistry', () => ({
|
|
|
|
register: id => id,
|
|
|
|
getByID: () => mockEmptyObject,
|
|
|
|
}));
|
2016-10-23 03:17:32 +00:00
|
|
|
|
|
|
|
jest.doMock('requireNativeComponent', () => {
|
|
|
|
const React = require('react');
|
|
|
|
|
2017-07-13 02:22:43 +00:00
|
|
|
return viewName => props => React.createElement(
|
|
|
|
viewName,
|
|
|
|
props,
|
|
|
|
props.children,
|
|
|
|
);
|
2016-10-23 03:17:32 +00:00
|
|
|
});
|