Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/jest-preset/jest/__tests__/setup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,31 @@

import NativeExceptionsManager from 'react-native/Libraries/Core/NativeExceptionsManager';

test('NativeAnimatedHelper is a mock', () => {
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation(() => {});

try {
const NativeAnimatedHelper: {
assertNativeAnimatedModule: () => void,
nativeEventEmitter: {addListener: () => void},
shouldUseNativeDriver: () => boolean,
} = jest.requireMock(
'react-native/src/private/animated/NativeAnimatedHelper',
).default;

expect(
jest.isMockFunction(NativeAnimatedHelper.assertNativeAnimatedModule),
).toBe(true);
expect(NativeAnimatedHelper.nativeEventEmitter).toBeDefined();
expect(
jest.isMockFunction(NativeAnimatedHelper.shouldUseNativeDriver),
).toBe(false);
expect(consoleWarn).not.toHaveBeenCalled();
} finally {
consoleWarn.mockRestore();
}
});

test('NativeExceptionsManager is a mock', () => {
expect(jest.isMockFunction(NativeExceptionsManager.reportException)).toBe(
true,
Expand Down
22 changes: 22 additions & 0 deletions packages/jest-preset/jest/mocks/NativeAnimatedHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/

import typeof TNativeAnimatedHelper from 'react-native/src/private/animated/NativeAnimatedHelper';

const NativeAnimatedHelper = jest.requireActual<{
default: TNativeAnimatedHelper,
}>('react-native/src/private/animated/NativeAnimatedHelper').default;

const NativeAnimatedHelperMock: TNativeAnimatedHelper = {
...NativeAnimatedHelper,
assertNativeAnimatedModule: jest.fn(),
};

export default NativeAnimatedHelperMock;
4 changes: 4 additions & 0 deletions packages/jest-preset/jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,7 @@ mock(
// $FlowFixMe[incompatible-type]
'm#./mocks/Vibration',
);
mock(
'm#react-native/src/private/animated/NativeAnimatedHelper',
'm#./mocks/NativeAnimatedHelper',
);
Loading