@react-native/jest-preset 0.85.0-nightly-20260219-44901aaf9
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/README.md +39 -0
- package/jest/MockNativeMethods.js +27 -0
- package/jest/RefreshControlMock.js +32 -0
- package/jest/assetFileTransformer.js +38 -0
- package/jest/local-setup.js +29 -0
- package/jest/mock.js +39 -0
- package/jest/mockComponent.js +103 -0
- package/jest/mockNativeComponent.js +52 -0
- package/jest/mocks/AccessibilityInfo.js +62 -0
- package/jest/mocks/ActivityIndicator.js +23 -0
- package/jest/mocks/AppState.js +19 -0
- package/jest/mocks/Clipboard.js +16 -0
- package/jest/mocks/Image.js +23 -0
- package/jest/mocks/InitializeCore.js +9 -0
- package/jest/mocks/Linking.js +28 -0
- package/jest/mocks/Modal.js +33 -0
- package/jest/mocks/NativeComponentRegistry.js +30 -0
- package/jest/mocks/NativeModules.js +239 -0
- package/jest/mocks/RefreshControl.js +31 -0
- package/jest/mocks/RendererProxy.js +45 -0
- package/jest/mocks/ScrollView.js +58 -0
- package/jest/mocks/Text.js +27 -0
- package/jest/mocks/TextInput.js +32 -0
- package/jest/mocks/UIManager.js +60 -0
- package/jest/mocks/Vibration.js +16 -0
- package/jest/mocks/View.js +27 -0
- package/jest/mocks/ViewNativeComponent.js +23 -0
- package/jest/mocks/requireNativeComponent.js +22 -0
- package/jest/mocks/useColorScheme.js +18 -0
- package/jest/react-native-env.js +17 -0
- package/jest/renderer.js +40 -0
- package/jest/resolver.js +32 -0
- package/jest/setup.js +177 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @react-native/jest-preset
|
|
2
|
+
|
|
3
|
+
Jest preset for [React Native](https://reactnative.dev) apps.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
### Installation
|
|
8
|
+
|
|
9
|
+
Install `@react-native/jest-preset` in your app:
|
|
10
|
+
|
|
11
|
+
with `npm`:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm i @react-native/jest-preset --save-dev
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
or with `yarn`:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
yarn add -D @react-native/jest-preset
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Configuring Jest
|
|
24
|
+
|
|
25
|
+
Then, create a file called `jest.config.js` in your project's root directory. Then load this preset:
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
module.exports = {
|
|
29
|
+
preset: '@react-native/jest-preset',
|
|
30
|
+
};
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
You can further customize your Jest configuration by specifying other options. See [Jest's `jest.config.js` documentation](https://jestjs.io/docs/configuration) to learn more.
|
|
34
|
+
|
|
35
|
+
### Migration Note
|
|
36
|
+
|
|
37
|
+
This Jest preset used to be part of the core `react-native` package and accessible at `react-native/jest-preset.js`. As long as `@react-native/jest-preset` is installed, `react-native/jest-preset.js` will be aliased to this package and continue to work but is deprecated.
|
|
38
|
+
|
|
39
|
+
Follow the installation instructions above to migrate to `@react-native/jest-preset` and change `preset: 'react-native'` to `preset: '@react-native/jest-preset` to migrate.
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const MockNativeMethods = {
|
|
12
|
+
measure: jest.fn(),
|
|
13
|
+
measureInWindow: jest.fn(),
|
|
14
|
+
measureLayout: jest.fn(),
|
|
15
|
+
setNativeProps: jest.fn(),
|
|
16
|
+
focus: jest.fn(),
|
|
17
|
+
blur: jest.fn(),
|
|
18
|
+
} as {
|
|
19
|
+
measure: () => void,
|
|
20
|
+
measureInWindow: () => void,
|
|
21
|
+
measureLayout: () => void,
|
|
22
|
+
setNativeProps: () => void,
|
|
23
|
+
focus: () => void,
|
|
24
|
+
blur: () => void,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default MockNativeMethods;
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
import type {HostComponent} from 'react-native/src/private/types/HostComponent';
|
|
14
|
+
|
|
15
|
+
import * as React from 'react';
|
|
16
|
+
import requireNativeComponent from 'react-native/Libraries/ReactNative/requireNativeComponent';
|
|
17
|
+
|
|
18
|
+
const RCTRefreshControl: HostComponent<{}> = requireNativeComponent<{}>(
|
|
19
|
+
'RCTRefreshControl',
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export default class RefreshControlMock extends React.Component<{...}> {
|
|
23
|
+
static latestRef: ?RefreshControlMock;
|
|
24
|
+
|
|
25
|
+
render(): React.Node {
|
|
26
|
+
return <RCTRefreshControl />;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
componentDidMount() {
|
|
30
|
+
RefreshControlMock.latestRef = this;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
* @noflow
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
/* eslint-env node */
|
|
14
|
+
|
|
15
|
+
const createCacheKeyFunction =
|
|
16
|
+
require('@jest/create-cache-key-function').default;
|
|
17
|
+
const path = require('path');
|
|
18
|
+
|
|
19
|
+
// NOTE: This file used to be at `react-native/jest/assetFileTransformer.js`
|
|
20
|
+
// To keep the mock `testUri` paths the same, we create a fake path that outputs the same relative path as before
|
|
21
|
+
const basePath = path.resolve(
|
|
22
|
+
require.resolve('react-native/package.json'),
|
|
23
|
+
'../jest/',
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
module.exports = {
|
|
27
|
+
// Mocks asset requires to return the filename. Makes it possible to test that
|
|
28
|
+
// the correct images are loaded for components. Essentially
|
|
29
|
+
// require('img1.png') becomes `Object { "testUri": 'path/to/img1.png' }` in
|
|
30
|
+
// the Jest snapshot.
|
|
31
|
+
process: (_, filename) => ({
|
|
32
|
+
code: `module.exports = {
|
|
33
|
+
testUri:
|
|
34
|
+
${JSON.stringify(path.relative(basePath, filename).replace(/\\/g, '/'))}
|
|
35
|
+
};`,
|
|
36
|
+
}),
|
|
37
|
+
getCacheKey: createCacheKeyFunction([__filename]),
|
|
38
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// Global setup for tests local to the react-native repo. This setup is not
|
|
12
|
+
// included in the react-native Jest preset.
|
|
13
|
+
|
|
14
|
+
import './setup';
|
|
15
|
+
|
|
16
|
+
const consoleError = console.error;
|
|
17
|
+
const consoleWarn = console.warn;
|
|
18
|
+
|
|
19
|
+
// $FlowFixMe[cannot-write]
|
|
20
|
+
console.error = (...args) => {
|
|
21
|
+
consoleError(...args);
|
|
22
|
+
throw new Error('console.error() was called (see error above)');
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// $FlowFixMe[cannot-write]
|
|
26
|
+
console.warn = (...args) => {
|
|
27
|
+
consoleWarn(...args);
|
|
28
|
+
throw new Error('console.warn() was called (see warning above)');
|
|
29
|
+
};
|
package/jest/mock.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Mocks the module referenced by `moduleRef` (expected to begin with `m#`)
|
|
14
|
+
* while enforcing type safety of mock factories.
|
|
15
|
+
*
|
|
16
|
+
* If `factoryRef` is provided, it is expected to reference a module that
|
|
17
|
+
* exports the same type signature as the module referenced by `moduleRef`.
|
|
18
|
+
*/
|
|
19
|
+
export default function mock<TModuleRef: $Flow$ModuleRef<unknown>>(
|
|
20
|
+
moduleRef: TModuleRef,
|
|
21
|
+
factoryRef?: NoInfer<TModuleRef>,
|
|
22
|
+
): void {
|
|
23
|
+
// NOTE: Jest's `babel-plugin-jest-hoist` requires that the second argument to
|
|
24
|
+
// `jest.mock` be an inline function, so structure this code accordingly.
|
|
25
|
+
if (factoryRef === undefined) {
|
|
26
|
+
jest.mock(deref(moduleRef));
|
|
27
|
+
} else {
|
|
28
|
+
// NOTE: Jest's `babel-plugin-jest-hoist` requires that module factories
|
|
29
|
+
// only reference local variables or variables starting with "mock", so be
|
|
30
|
+
// careful when renaming this `mockFactory` variable.
|
|
31
|
+
const mockFactory = deref(factoryRef);
|
|
32
|
+
jest.mock(deref(moduleRef), () => jest.requireActual(mockFactory));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function deref(ref: $Flow$ModuleRef<unknown>): string {
|
|
37
|
+
// $FlowFixMe[incompatible-type]
|
|
38
|
+
return (ref as string).substring(2);
|
|
39
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import * as React from 'react';
|
|
12
|
+
import {createElement} from 'react';
|
|
13
|
+
|
|
14
|
+
type Modulish<T> = T | Readonly<{default: T}>;
|
|
15
|
+
type ModuleDefault<T> = T['default'];
|
|
16
|
+
|
|
17
|
+
type TComponentType = React.ComponentType<{...}>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* WARNING: The `moduleName` must be relative to this file's directory, which is
|
|
21
|
+
* a major footgun. Be careful when using this function!
|
|
22
|
+
*/
|
|
23
|
+
export default function mockComponent<
|
|
24
|
+
TComponentModule: Modulish<TComponentType>,
|
|
25
|
+
TIsESModule: boolean,
|
|
26
|
+
>(
|
|
27
|
+
moduleName: string,
|
|
28
|
+
instanceMethods: ?interface {},
|
|
29
|
+
isESModule: TIsESModule,
|
|
30
|
+
): TIsESModule extends true // $FlowFixMe[incompatible-use]
|
|
31
|
+
? ModuleDefault<TComponentModule & typeof instanceMethods>
|
|
32
|
+
: TComponentModule & typeof instanceMethods {
|
|
33
|
+
const RealComponent: TComponentType = isESModule
|
|
34
|
+
? // $FlowFixMe[prop-missing]
|
|
35
|
+
jest.requireActual<TComponentModule>(moduleName).default
|
|
36
|
+
: // $FlowFixMe[incompatible-type]
|
|
37
|
+
jest.requireActual<TComponentModule>(moduleName);
|
|
38
|
+
|
|
39
|
+
const SuperClass: typeof React.Component<{...}> =
|
|
40
|
+
typeof RealComponent === 'function' &&
|
|
41
|
+
RealComponent.prototype?.constructor instanceof React.Component
|
|
42
|
+
? RealComponent
|
|
43
|
+
: React.Component;
|
|
44
|
+
|
|
45
|
+
const name =
|
|
46
|
+
RealComponent.displayName ??
|
|
47
|
+
RealComponent.name ??
|
|
48
|
+
// $FlowFixMe[prop-missing] - Checking for `forwardRef` values.
|
|
49
|
+
(RealComponent.render == null
|
|
50
|
+
? 'Unknown'
|
|
51
|
+
: // $FlowFixMe[incompatible-use]
|
|
52
|
+
(RealComponent.render.displayName ?? RealComponent.render.name));
|
|
53
|
+
|
|
54
|
+
const nameWithoutPrefix = name.replace(/^(RCT|RK)/, '');
|
|
55
|
+
|
|
56
|
+
const Component = class extends SuperClass {
|
|
57
|
+
static displayName: ?string = 'Component';
|
|
58
|
+
|
|
59
|
+
render(): React.Node {
|
|
60
|
+
// $FlowFixMe[prop-missing]
|
|
61
|
+
const props = {...RealComponent.defaultProps};
|
|
62
|
+
|
|
63
|
+
if (this.props) {
|
|
64
|
+
Object.keys(this.props).forEach(prop => {
|
|
65
|
+
// We can't just assign props on top of defaultProps
|
|
66
|
+
// because React treats undefined as special and different from null.
|
|
67
|
+
// If a prop is specified but set to undefined it is ignored and the
|
|
68
|
+
// default prop is used instead. If it is set to null, then the
|
|
69
|
+
// null value overwrites the default value.
|
|
70
|
+
if (this.props[prop] !== undefined) {
|
|
71
|
+
props[prop] = this.props[prop];
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// $FlowFixMe[not-a-function]
|
|
77
|
+
// $FlowFixMe[prop-missing]
|
|
78
|
+
return createElement(nameWithoutPrefix, props, this.props.children);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
Object.defineProperty(Component, 'name', {
|
|
83
|
+
value: name,
|
|
84
|
+
writable: false,
|
|
85
|
+
enumerable: false,
|
|
86
|
+
configurable: true,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
Component.displayName = nameWithoutPrefix;
|
|
90
|
+
|
|
91
|
+
// $FlowFixMe[not-an-object]
|
|
92
|
+
Object.keys(RealComponent).forEach(classStatic => {
|
|
93
|
+
Component[classStatic] = RealComponent[classStatic];
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (instanceMethods != null) {
|
|
97
|
+
// $FlowFixMe[unsafe-object-assign]
|
|
98
|
+
Object.assign(Component.prototype, instanceMethods);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// $FlowFixMe[incompatible-type]
|
|
102
|
+
return Component;
|
|
103
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {HostInstance} from 'react-native/src/private/types/HostInstance';
|
|
12
|
+
|
|
13
|
+
import * as React from 'react';
|
|
14
|
+
import {createElement} from 'react';
|
|
15
|
+
|
|
16
|
+
let nativeTag = 1;
|
|
17
|
+
|
|
18
|
+
type MockNativeComponent<TProps: {...}> = component(
|
|
19
|
+
ref?: ?React.RefSetter<HostInstance>,
|
|
20
|
+
...props: TProps
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export default function mockNativeComponent<TProps: {...}>(
|
|
24
|
+
viewName: string,
|
|
25
|
+
): MockNativeComponent<TProps> {
|
|
26
|
+
const Component = class extends React.Component<TProps> {
|
|
27
|
+
_nativeTag: number = nativeTag++;
|
|
28
|
+
|
|
29
|
+
render(): React.Node {
|
|
30
|
+
// $FlowFixMe[not-a-function]
|
|
31
|
+
// $FlowFixMe[prop-missing]
|
|
32
|
+
return createElement(viewName, this.props, this.props.children);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// The methods that exist on host components
|
|
36
|
+
blur: () => void = jest.fn();
|
|
37
|
+
focus: () => void = jest.fn();
|
|
38
|
+
measure: () => void = jest.fn();
|
|
39
|
+
measureInWindow: () => void = jest.fn();
|
|
40
|
+
measureLayout: () => void = jest.fn();
|
|
41
|
+
setNativeProps: () => void = jest.fn();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
if (viewName === 'RCTView') {
|
|
45
|
+
Component.displayName = 'View';
|
|
46
|
+
} else {
|
|
47
|
+
Component.displayName = viewName;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// $FlowFixMe[incompatible-type] - Error supressed during the migration of HostInstance to ReactNativeElement
|
|
51
|
+
return Component;
|
|
52
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const AccessibilityInfo = {
|
|
12
|
+
addEventListener: jest.fn(() => ({
|
|
13
|
+
remove: jest.fn(),
|
|
14
|
+
})) as JestMockFn<$FlowFixMe, {remove: JestMockFn<[], void>}>,
|
|
15
|
+
announceForAccessibility: jest.fn() as JestMockFn<$FlowFixMe, $FlowFixMe>,
|
|
16
|
+
announceForAccessibilityWithOptions: jest.fn() as JestMockFn<
|
|
17
|
+
$FlowFixMe,
|
|
18
|
+
$FlowFixMe,
|
|
19
|
+
>,
|
|
20
|
+
isAccessibilityServiceEnabled: jest.fn(() =>
|
|
21
|
+
Promise.resolve(false),
|
|
22
|
+
) as JestMockFn<$FlowFixMe, $FlowFixMe>,
|
|
23
|
+
isBoldTextEnabled: jest.fn(() => Promise.resolve(false)) as JestMockFn<
|
|
24
|
+
$FlowFixMe,
|
|
25
|
+
$FlowFixMe,
|
|
26
|
+
>,
|
|
27
|
+
isGrayscaleEnabled: jest.fn(() => Promise.resolve(false)) as JestMockFn<
|
|
28
|
+
$FlowFixMe,
|
|
29
|
+
$FlowFixMe,
|
|
30
|
+
>,
|
|
31
|
+
isInvertColorsEnabled: jest.fn(() => Promise.resolve(false)) as JestMockFn<
|
|
32
|
+
$FlowFixMe,
|
|
33
|
+
$FlowFixMe,
|
|
34
|
+
>,
|
|
35
|
+
isReduceMotionEnabled: jest.fn(() => Promise.resolve(false)) as JestMockFn<
|
|
36
|
+
$FlowFixMe,
|
|
37
|
+
$FlowFixMe,
|
|
38
|
+
>,
|
|
39
|
+
isHighTextContrastEnabled: jest.fn(() =>
|
|
40
|
+
Promise.resolve(false),
|
|
41
|
+
) as JestMockFn<$FlowFixMe, $FlowFixMe>,
|
|
42
|
+
isDarkerSystemColorsEnabled: jest.fn(() =>
|
|
43
|
+
Promise.resolve(false),
|
|
44
|
+
) as JestMockFn<$FlowFixMe, $FlowFixMe>,
|
|
45
|
+
prefersCrossFadeTransitions: jest.fn(() =>
|
|
46
|
+
Promise.resolve(false),
|
|
47
|
+
) as JestMockFn<$FlowFixMe, $FlowFixMe>,
|
|
48
|
+
isReduceTransparencyEnabled: jest.fn(() =>
|
|
49
|
+
Promise.resolve(false),
|
|
50
|
+
) as JestMockFn<$FlowFixMe, $FlowFixMe>,
|
|
51
|
+
isScreenReaderEnabled: jest.fn(() => Promise.resolve(false)) as JestMockFn<
|
|
52
|
+
$FlowFixMe,
|
|
53
|
+
$FlowFixMe,
|
|
54
|
+
>,
|
|
55
|
+
setAccessibilityFocus: jest.fn() as JestMockFn<$FlowFixMe, $FlowFixMe>,
|
|
56
|
+
sendAccessibilityEvent: jest.fn() as JestMockFn<$FlowFixMe, $FlowFixMe>,
|
|
57
|
+
getRecommendedTimeoutMillis: jest.fn(() =>
|
|
58
|
+
Promise.resolve(false),
|
|
59
|
+
) as JestMockFn<$FlowFixMe, $FlowFixMe>,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default AccessibilityInfo;
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import typeof * as TmockComponent from '../mockComponent';
|
|
12
|
+
import typeof TActivityIndicator from 'react-native/Libraries/Components/ActivityIndicator/ActivityIndicator';
|
|
13
|
+
|
|
14
|
+
const mockComponent =
|
|
15
|
+
jest.requireActual<TmockComponent>('../mockComponent').default;
|
|
16
|
+
|
|
17
|
+
const ActivityIndicator = mockComponent(
|
|
18
|
+
'react-native/Libraries/Components/ActivityIndicator/ActivityIndicator',
|
|
19
|
+
null, // instanceMethods
|
|
20
|
+
true, // isESModule
|
|
21
|
+
) as TActivityIndicator;
|
|
22
|
+
|
|
23
|
+
export default ActivityIndicator;
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const AppState = {
|
|
12
|
+
addEventListener: jest.fn(() => ({
|
|
13
|
+
remove: jest.fn(),
|
|
14
|
+
})) as JestMockFn<$FlowFixMe, $FlowFixMe>,
|
|
15
|
+
removeEventListener: jest.fn() as JestMockFn<$FlowFixMe, $FlowFixMe>,
|
|
16
|
+
currentState: jest.fn() as JestMockFn<$FlowFixMe, $FlowFixMe>,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default AppState;
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const Clipboard = {
|
|
12
|
+
getString: jest.fn(async () => '') as JestMockFn<[], Promise<string>>,
|
|
13
|
+
setString: jest.fn() as JestMockFn<[string], void>,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default Clipboard;
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import typeof * as TmockComponent from '../mockComponent';
|
|
12
|
+
import typeof TImage from 'react-native/Libraries/Image/Image';
|
|
13
|
+
|
|
14
|
+
const mockComponent =
|
|
15
|
+
jest.requireActual<TmockComponent>('../mockComponent').default;
|
|
16
|
+
|
|
17
|
+
const Image = mockComponent(
|
|
18
|
+
'react-native/Libraries/Image/Image',
|
|
19
|
+
null, // instanceMethods
|
|
20
|
+
true, // isESModule
|
|
21
|
+
) as TImage;
|
|
22
|
+
|
|
23
|
+
export default Image;
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const Linking = {
|
|
12
|
+
openURL: jest.fn() as JestMockFn<$FlowFixMe, $FlowFixMe>,
|
|
13
|
+
canOpenURL: jest.fn(() => Promise.resolve(true)) as JestMockFn<
|
|
14
|
+
$FlowFixMe,
|
|
15
|
+
$FlowFixMe,
|
|
16
|
+
>,
|
|
17
|
+
openSettings: jest.fn() as JestMockFn<$FlowFixMe, $FlowFixMe>,
|
|
18
|
+
addEventListener: jest.fn(() => ({
|
|
19
|
+
remove: jest.fn(),
|
|
20
|
+
})) as JestMockFn<$FlowFixMe, $FlowFixMe>,
|
|
21
|
+
getInitialURL: jest.fn(() => Promise.resolve()) as JestMockFn<
|
|
22
|
+
$FlowFixMe,
|
|
23
|
+
$FlowFixMe,
|
|
24
|
+
>,
|
|
25
|
+
sendIntent: jest.fn() as JestMockFn<$FlowFixMe, $FlowFixMe>,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default Linking;
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import typeof * as TmockComponent from '../mockComponent';
|
|
12
|
+
import type {ModalProps} from 'react-native/Libraries/Modal/Modal';
|
|
13
|
+
|
|
14
|
+
const mockComponent =
|
|
15
|
+
jest.requireActual<TmockComponent>('../mockComponent').default;
|
|
16
|
+
|
|
17
|
+
type TModal = component(...ModalProps);
|
|
18
|
+
|
|
19
|
+
const BaseComponent = mockComponent(
|
|
20
|
+
'react-native/Libraries/Modal/Modal',
|
|
21
|
+
null, // instanceMethods
|
|
22
|
+
true, // isESModule
|
|
23
|
+
) as TModal;
|
|
24
|
+
|
|
25
|
+
// $FlowFixMe[incompatible-use]
|
|
26
|
+
export default class Modal extends BaseComponent {
|
|
27
|
+
render(): React.Node {
|
|
28
|
+
if (this.props.visible === false) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return <BaseComponent {...this.props}>{this.props.children}</BaseComponent>;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import typeof * as TmockNativeComponent from '../mockNativeComponent';
|
|
12
|
+
|
|
13
|
+
const mockNativeComponent = jest.requireActual<TmockNativeComponent>(
|
|
14
|
+
'../mockNativeComponent',
|
|
15
|
+
).default;
|
|
16
|
+
|
|
17
|
+
export const get = jest.fn((name, viewConfigProvider) => {
|
|
18
|
+
return mockNativeComponent(name);
|
|
19
|
+
}) as JestMockFn<$FlowFixMe, $FlowFixMe>;
|
|
20
|
+
|
|
21
|
+
export const getWithFallback_DEPRECATED = jest.fn(
|
|
22
|
+
(name, viewConfigProvider) => {
|
|
23
|
+
return mockNativeComponent(name);
|
|
24
|
+
},
|
|
25
|
+
) as JestMockFn<$FlowFixMe, $FlowFixMe>;
|
|
26
|
+
|
|
27
|
+
export const setRuntimeConfigProvider = jest.fn() as JestMockFn<
|
|
28
|
+
$FlowFixMe,
|
|
29
|
+
$FlowFixMe,
|
|
30
|
+
>;
|