Created
February 20, 2022 13:16
-
-
Save Stringsaeed/fd0e47351eea86003a98d97eb6ba2654 to your computer and use it in GitHub Desktop.
React Native setup jest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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