react-native-safe-area-context
react-native-safe-area-context copied to clipboard
Missing types for react-native-safe-area-context/jest/mock
Hello,
When setting up the mock for jest, I face a typescript error:
Could not find a declaration file for module 'react-native-safe-area-context/jest/mock'.
The mock is currently a JS file, would it be possible to rewrite it to TS or provide a definition for it?
I do not know this module too much (RN beginner here), but I managed to workaround with that local definition:
// react-native-safe-area-context.d.ts
declare module 'react-native-safe-area-context/jest/mock' {
import RNSafeAreaContext, { Metrics, SafeAreaViewProps } from 'react-native-safe-area-context';
export const initialWindowMetrics: Metrics;
export const SafeAreaProvider: React.FC<SafeAreaViewProps>;
export default RNSafeAreaContext;
}
It works for me with TS v4.4, however I am not sure how relevant it is regarding this module. (I just tried to reproduce what the mock is currently doing)
I believe you have to use this file to create your own mock in your Jest environment setup, like this:
jest.mock('react-native-safe-area-context', () => require('react-native-safe-area-context/jest/mock').default);
This way the library is mocked globally in Jest and you shouldn't get any complaints from TS
Same problem
Please continue discussion https://github.com/th3rdwave/react-native-safe-area-context/pull/231