|
| 1 | +/** |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @format |
| 8 | + */ |
| 9 | + |
| 10 | +'use strict'; |
| 11 | + |
| 12 | +jest.requireActual('@react-native/js-polyfills/error-guard'); |
| 13 | + |
| 14 | +jest |
| 15 | + .mock('react-native/Libraries/ReactNative/UIManager', () => ({ |
| 16 | + AndroidViewPager: { |
| 17 | + Commands: { |
| 18 | + setPage: jest.fn(), |
| 19 | + setPageWithoutAnimation: jest.fn(), |
| 20 | + }, |
| 21 | + }, |
| 22 | + blur: jest.fn(), |
| 23 | + createView: jest.fn(), |
| 24 | + customBubblingEventTypes: {}, |
| 25 | + customDirectEventTypes: {}, |
| 26 | + getConstants: () => ({ |
| 27 | + ViewManagerNames: [], |
| 28 | + }), |
| 29 | + getDefaultEventTypes: jest.fn(), |
| 30 | + dispatchViewManagerCommand: jest.fn(), |
| 31 | + focus: jest.fn(), |
| 32 | + getViewManagerConfig: jest.fn(name => { |
| 33 | + if (name === 'AndroidDrawerLayout') { |
| 34 | + return { |
| 35 | + Constants: { |
| 36 | + DrawerPosition: { |
| 37 | + Left: 10, |
| 38 | + }, |
| 39 | + }, |
| 40 | + }; |
| 41 | + } |
| 42 | + |
| 43 | + return {NativeProps: {}}; |
| 44 | + }), |
| 45 | + hasViewManagerConfig: jest.fn(name => { |
| 46 | + return name === 'AndroidDrawerLayout'; |
| 47 | + }), |
| 48 | + measure: jest.fn(), |
| 49 | + manageChildren: jest.fn(), |
| 50 | + removeSubviewsFromContainerWithID: jest.fn(), |
| 51 | + replaceExistingNonRootView: jest.fn(), |
| 52 | + setChildren: jest.fn(), |
| 53 | + updateView: jest.fn(), |
| 54 | + AndroidDrawerLayout: { |
| 55 | + Constants: { |
| 56 | + DrawerPosition: { |
| 57 | + Left: 10, |
| 58 | + }, |
| 59 | + }, |
| 60 | + }, |
| 61 | + AndroidTextInput: { |
| 62 | + Commands: {}, |
| 63 | + }, |
| 64 | + ScrollView: { |
| 65 | + Constants: {}, |
| 66 | + }, |
| 67 | + View: { |
| 68 | + Constants: {}, |
| 69 | + }, |
| 70 | + })) |
| 71 | + // Mock modules defined by the native layer (ex: Objective-C, Java) |
| 72 | + .mock('react-native/Libraries/BatchedBridge/NativeModules', () => ({ |
| 73 | + AlertManager: { |
| 74 | + alertWithArgs: jest.fn(), |
| 75 | + }, |
| 76 | + AsyncLocalStorage: { |
| 77 | + multiGet: jest.fn((keys, callback) => |
| 78 | + process.nextTick(() => callback(null, [])), |
| 79 | + ), |
| 80 | + multiSet: jest.fn((entries, callback) => |
| 81 | + process.nextTick(() => callback(null)), |
| 82 | + ), |
| 83 | + multiRemove: jest.fn((keys, callback) => |
| 84 | + process.nextTick(() => callback(null)), |
| 85 | + ), |
| 86 | + multiMerge: jest.fn((entries, callback) => |
| 87 | + process.nextTick(() => callback(null)), |
| 88 | + ), |
| 89 | + clear: jest.fn(callback => process.nextTick(() => callback(null))), |
| 90 | + getAllKeys: jest.fn(callback => |
| 91 | + process.nextTick(() => callback(null, [])), |
| 92 | + ), |
| 93 | + }, |
| 94 | + DeviceInfo: { |
| 95 | + getConstants() { |
| 96 | + return { |
| 97 | + Dimensions: { |
| 98 | + window: { |
| 99 | + fontScale: 2, |
| 100 | + height: 1334, |
| 101 | + scale: 2, |
| 102 | + width: 750, |
| 103 | + }, |
| 104 | + screen: { |
| 105 | + fontScale: 2, |
| 106 | + height: 1334, |
| 107 | + scale: 2, |
| 108 | + width: 750, |
| 109 | + }, |
| 110 | + }, |
| 111 | + }; |
| 112 | + }, |
| 113 | + }, |
| 114 | + DevSettings: { |
| 115 | + addMenuItem: jest.fn(), |
| 116 | + reload: jest.fn(), |
| 117 | + }, |
| 118 | + ImageLoader: { |
| 119 | + getSize: jest.fn(url => Promise.resolve([320, 240])), |
| 120 | + prefetchImage: jest.fn(), |
| 121 | + }, |
| 122 | + ImageViewManager: { |
| 123 | + getSize: jest.fn((uri, success) => |
| 124 | + process.nextTick(() => success(320, 240)), |
| 125 | + ), |
| 126 | + prefetchImage: jest.fn(), |
| 127 | + }, |
| 128 | + KeyboardObserver: { |
| 129 | + addListener: jest.fn(), |
| 130 | + removeListeners: jest.fn(), |
| 131 | + }, |
| 132 | + Networking: { |
| 133 | + sendRequest: jest.fn(), |
| 134 | + abortRequest: jest.fn(), |
| 135 | + addListener: jest.fn(), |
| 136 | + removeListeners: jest.fn(), |
| 137 | + }, |
| 138 | + PlatformConstants: { |
| 139 | + getConstants() { |
| 140 | + return { |
| 141 | + reactNativeVersion: { |
| 142 | + major: 1000, |
| 143 | + minor: 0, |
| 144 | + patch: 0, |
| 145 | + }, |
| 146 | + }; |
| 147 | + }, |
| 148 | + }, |
| 149 | + PushNotificationManager: { |
| 150 | + presentLocalNotification: jest.fn(), |
| 151 | + scheduleLocalNotification: jest.fn(), |
| 152 | + cancelAllLocalNotifications: jest.fn(), |
| 153 | + removeAllDeliveredNotifications: jest.fn(), |
| 154 | + getDeliveredNotifications: jest.fn(callback => |
| 155 | + process.nextTick(() => []), |
| 156 | + ), |
| 157 | + removeDeliveredNotifications: jest.fn(), |
| 158 | + setApplicationIconBadgeNumber: jest.fn(), |
| 159 | + getApplicationIconBadgeNumber: jest.fn(callback => |
| 160 | + process.nextTick(() => callback(0)), |
| 161 | + ), |
| 162 | + cancelLocalNotifications: jest.fn(), |
| 163 | + getScheduledLocalNotifications: jest.fn(callback => |
| 164 | + process.nextTick(() => callback()), |
| 165 | + ), |
| 166 | + requestPermissions: jest.fn(() => |
| 167 | + Promise.resolve({alert: true, badge: true, sound: true}), |
| 168 | + ), |
| 169 | + abandonPermissions: jest.fn(), |
| 170 | + checkPermissions: jest.fn(callback => |
| 171 | + process.nextTick(() => |
| 172 | + callback({alert: true, badge: true, sound: true}), |
| 173 | + ), |
| 174 | + ), |
| 175 | + getInitialNotification: jest.fn(() => Promise.resolve(null)), |
| 176 | + addListener: jest.fn(), |
| 177 | + removeListeners: jest.fn(), |
| 178 | + }, |
| 179 | + StatusBarManager: { |
| 180 | + setColor: jest.fn(), |
| 181 | + setStyle: jest.fn(), |
| 182 | + setHidden: jest.fn(), |
| 183 | + setNetworkActivityIndicatorVisible: jest.fn(), |
| 184 | + setBackgroundColor: jest.fn(), |
| 185 | + setTranslucent: jest.fn(), |
| 186 | + getConstants: () => ({ |
| 187 | + HEIGHT: 42, |
| 188 | + }), |
| 189 | + }, |
| 190 | + Timing: { |
| 191 | + createTimer: jest.fn(), |
| 192 | + deleteTimer: jest.fn(), |
| 193 | + }, |
| 194 | + UIManager: {}, |
| 195 | + BlobModule: { |
| 196 | + getConstants: () => ({BLOB_URI_SCHEME: 'content', BLOB_URI_HOST: null}), |
| 197 | + addNetworkingHandler: jest.fn(), |
| 198 | + enableBlobSupport: jest.fn(), |
| 199 | + disableBlobSupport: jest.fn(), |
| 200 | + createFromParts: jest.fn(), |
| 201 | + sendBlob: jest.fn(), |
| 202 | + release: jest.fn(), |
| 203 | + }, |
| 204 | + WebSocketModule: { |
| 205 | + connect: jest.fn(), |
| 206 | + send: jest.fn(), |
| 207 | + sendBinary: jest.fn(), |
| 208 | + ping: jest.fn(), |
| 209 | + close: jest.fn(), |
| 210 | + addListener: jest.fn(), |
| 211 | + removeListeners: jest.fn(), |
| 212 | + }, |
| 213 | + I18nManager: { |
| 214 | + allowRTL: jest.fn(), |
| 215 | + forceRTL: jest.fn(), |
| 216 | + swapLeftAndRightInRTL: jest.fn(), |
| 217 | + getConstants: () => ({ |
| 218 | + isRTL: false, |
| 219 | + doLeftAndRightSwapInRTL: true, |
| 220 | + }), |
| 221 | + }, |
| 222 | + })); |
0 commit comments