Skip to content

Instantly share code, notes, and snippets.

@Stringsaeed
Created February 20, 2022 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stringsaeed/fd0e47351eea86003a98d97eb6ba2654 to your computer and use it in GitHub Desktop.
Save Stringsaeed/fd0e47351eea86003a98d97eb6ba2654 to your computer and use it in GitHub Desktop.
React Native setup jest
import 'react-native-gesture-handler/jestSetup';
import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock';
require('react-native-reanimated/lib/reanimated2/jestUtils').setUpTests();
jest.useFakeTimers();
jest.mock('react-native-reanimated', () => {
const Reanimated = require('react-native-reanimated/mock');
// The mock for `call` immediately calls the callback which is incorrect
// So we override it with a no-op
Reanimated.default.call = () => {};
return Reanimated;
});
// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter');
jest.mock('@react-native-async-storage/async-storage', () => mockAsyncStorage);
global.__reanimatedWorkletInit = jest.fn();
jest.mock('react-native-redash', () => ({
clamp: jest.fn(),
}));
jest.mock('react-native/Libraries/Utilities/Platform', () => {
const Platform = jest.requireActual(
'react-native/Libraries/Utilities/Platform',
);
Platform.constants.reactNativeVersion = {major: 0, minor: 64, patch: 0};
return Platform;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment