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-02-02 13:30:03 +00:00
|
|
|
require.requireActual('../packager/src/Resolver/polyfills/babelHelpers.js');
|
|
|
|
require.requireActual('../packager/src/Resolver/polyfills/Object.es7.js');
|
|
|
|
require.requireActual('../packager/src/Resolver/polyfills/error-guard');
|
2016-10-17 15:40:11 +00:00
|
|
|
|
|
|
|
global.__DEV__ = true;
|
|
|
|
|
|
|
|
global.Promise = require.requireActual('promise');
|
|
|
|
global.regeneratorRuntime = require.requireActual('regenerator-runtime/runtime');
|
|
|
|
|
|
|
|
jest
|
2016-10-31 19:52:30 +00:00
|
|
|
.mock('setupDevtools')
|
2016-10-17 15:40:11 +00:00
|
|
|
.mock('npmlog');
|
|
|
|
|
|
|
|
// 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'))
|
2016-10-17 15:40:11 +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 => {
|
2016-12-21 15:54:49 +00:00
|
|
|
this.items += dataBlob[key] && (
|
|
|
|
dataBlob[key].length || dataBlob[key].size || 0
|
2017-02-08 22:38:37 +00:00
|
|
|
);
|
2016-10-17 15:40:11 +00:00
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
this.items = 'unknown';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ListViewDataSource(this._dataBlob);
|
|
|
|
};
|
|
|
|
return DataSource;
|
|
|
|
})
|
|
|
|
.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-04-13 13:17:15 +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))),
|
|
|
|
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: {
|
|
|
|
getSize: jest.fn(
|
|
|
|
(uri, success) => process.nextTick(() => success(320, 240))
|
|
|
|
),
|
|
|
|
prefetchImage: jest.fn(),
|
|
|
|
},
|
|
|
|
ImageViewManager: {
|
|
|
|
getSize: jest.fn(
|
|
|
|
(uri, success) => process.nextTick(() => success(320, 240))
|
|
|
|
),
|
|
|
|
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(),
|
|
|
|
canOpenURL: jest.fn(
|
|
|
|
() => new Promise((resolve) => resolve(true))
|
|
|
|
),
|
|
|
|
},
|
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: {},
|
2016-10-31 19:52:30 +00:00
|
|
|
Networking: {
|
|
|
|
sendRequest: jest.fn(),
|
|
|
|
abortRequest: jest.fn(),
|
|
|
|
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-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');
|
|
|
|
|
|
|
|
return viewName => props => React.createElement(
|
|
|
|
viewName,
|
|
|
|
props,
|
|
|
|
props.children,
|
|
|
|
);
|
|
|
|
});
|