jest-expo 52.0.0-preview.1 → 52.0.0-preview.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/preset/setup.js +23 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jest-expo",
|
|
3
|
-
"version": "52.0.0-preview.
|
|
3
|
+
"version": "52.0.0-preview.2",
|
|
4
4
|
"description": "A Jest preset to painlessly test your Expo / React Native apps.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"expo": "*",
|
|
60
60
|
"react-native": "*"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "8b9f5addf49cb5ef7598ca27ff60c0accff6a1c3"
|
|
63
63
|
}
|
package/src/preset/setup.js
CHANGED
|
@@ -241,6 +241,23 @@ try {
|
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
|
+
|
|
245
|
+
function requireMockModule(name) {
|
|
246
|
+
// Support auto-mocking of expo-modules that:
|
|
247
|
+
// 1. have a mock in the `mocks` directory
|
|
248
|
+
// 2. the native module (e.g. ExpoCrypto) name matches the package name (expo-crypto)
|
|
249
|
+
const nativeModuleMock = attemptLookup(name) ?? ExpoModulesCore.requireNativeModule(name);
|
|
250
|
+
if (!nativeModuleMock) {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const nativeModule = new NativeModule();
|
|
255
|
+
for (const [key, value] of Object.entries(nativeModuleMock)) {
|
|
256
|
+
nativeModule[key] = typeof value === 'function' ? jest.fn(value) : value;
|
|
257
|
+
}
|
|
258
|
+
return nativeModule;
|
|
259
|
+
}
|
|
260
|
+
|
|
244
261
|
return {
|
|
245
262
|
...ExpoModulesCore,
|
|
246
263
|
|
|
@@ -249,17 +266,13 @@ try {
|
|
|
249
266
|
NativeModule,
|
|
250
267
|
SharedObject,
|
|
251
268
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const nativeModule = new NativeModule();
|
|
258
|
-
|
|
259
|
-
for (const [key, value] of Object.entries(nativeModuleMock)) {
|
|
260
|
-
nativeModule[key] = typeof value === 'function' ? jest.fn(value) : value;
|
|
269
|
+
requireOptionalNativeModule: requireMockModule,
|
|
270
|
+
requireNativeModule(moduleName) {
|
|
271
|
+
const module = requireMockModule(moduleName);
|
|
272
|
+
if (!module) {
|
|
273
|
+
throw new Error(`Cannot find native module '${moduleName}'`);
|
|
261
274
|
}
|
|
262
|
-
return
|
|
275
|
+
return module;
|
|
263
276
|
},
|
|
264
277
|
requireNativeViewManager: (name) => {
|
|
265
278
|
const nativeModuleMock = attemptLookup(name);
|