th3rdwave / react-native-safe-area-context

A flexible way to handle safe area insets in JS. Also works on Android and Web!
MIT License
2.08k stars 191 forks source link

Extends mock capabilities and doc how to enable Babel parsing #449

Open LucasGarcez opened 8 months ago

LucasGarcez commented 8 months ago

Summary

Extends mock capabilities

Use jest.fn on useSafeAreaInsets and useSafeAreaFrame to allow the use of Mock Functions method as shown below:

import {useSafeAreaInsets} from 'react-native-safe-area-context';

const mockedUseSafeAreaInsets = jest.mocked(useSafeAreaInsets);
mockedUseSafeAreaInsets.mockImplementationOnce()

Improve documentation: Enabling Babel Parsing for Modules

Add a few lines to describe how to parse the mock file using jest config transformIgnorePatterns

transformIgnorePatterns: [
  'node_modules/(?!((jest-)?react-native|@react-native(-community)?|react-native-safe-area-context)/)',
];

Test Plan

Tested linking my react-native-safe-are-context fork as the dependency on my project: "react-native-safe-area-context": "git+https://github.com/LucasGarcez/react-native-safe-area-context.git#chore-improve-build-in-mock"

LucasGarcez commented 5 months ago

@janicduplessis any chance to merge this one? It's useful for folks who need to mock it.