Skip to content

Commit 8e09e9c

Browse files
rubennortefacebook-github-bot
authored andcommitted
Mock NativeAnimatedHelper in the Jest preset
Summary: Automatically mock `NativeAnimatedHelper` in the React Native Jest preset and add a regression test that verifies the helper is mocked. Changelog: [Internal] Differential Revision: D120986825
1 parent 8de8e08 commit 8e09e9c

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎packages/jest-preset/jest/__tests__/setup-test.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@
1010

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

13+
test('NativeAnimatedHelper is a mock', () => {
14+
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation(() => {});
15+
16+
try {
17+
const NativeAnimatedHelper: {
18+
assertNativeAnimatedModule: () => void,
19+
} = jest.requireMock(
20+
'react-native/src/private/animated/NativeAnimatedHelper',
21+
).default;
22+
23+
expect(
24+
jest.isMockFunction(NativeAnimatedHelper.assertNativeAnimatedModule),
25+
).toBe(true);
26+
expect(consoleWarn).not.toHaveBeenCalled();
27+
} finally {
28+
consoleWarn.mockRestore();
29+
}
30+
});
31+
1332
test('NativeExceptionsManager is a mock', () => {
1433
expect(jest.isMockFunction(NativeExceptionsManager.reportException)).toBe(
1534
true,

‎packages/jest-preset/jest/setup.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,4 @@ mock(
176176
// $FlowFixMe[incompatible-type]
177177
'm#./mocks/Vibration',
178178
);
179+
mock('m#react-native/src/private/animated/NativeAnimatedHelper');

0 commit comments

Comments
 (0)