Open LucasGarcez opened 8 months ago
Use jest.fn on useSafeAreaInsets and useSafeAreaFrame to allow the use of Mock Functions method as shown below:
jest.fn
useSafeAreaInsets
useSafeAreaFrame
import {useSafeAreaInsets} from 'react-native-safe-area-context'; const mockedUseSafeAreaInsets = jest.mocked(useSafeAreaInsets); mockedUseSafeAreaInsets.mockImplementationOnce()
Add a few lines to describe how to parse the mock file using jest config transformIgnorePatterns
transformIgnorePatterns
transformIgnorePatterns: [ 'node_modules/(?!((jest-)?react-native|@react-native(-community)?|react-native-safe-area-context)/)', ];
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"
"react-native-safe-area-context": "git+https://github.com/LucasGarcez/react-native-safe-area-context.git#chore-improve-build-in-mock"
@janicduplessis any chance to merge this one? It's useful for folks who need to mock it.
Summary
Extends mock capabilities
Use
jest.fn
onuseSafeAreaInsets
anduseSafeAreaFrame
to allow the use of Mock Functions method as shown below:Improve documentation: Enabling Babel Parsing for Modules
Add a few lines to describe how to parse the mock file using jest config
transformIgnorePatterns
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"