Testing | NativeBase | Universal Components for React and React Native

Search
K
Hire us
Data Display
Typography
Disclosure
Media and Icons
Others
If you are starting a new project, please try gluestack-ui for better performance and new design.
Testing
NativeBase works with react-native's jest preset or expo's jest-expo preset. However, there's one thing you'll need to do for it to work as expected.
Adding initialWindowMetrics in NativeBaseProvider.
NativeBaseProvider uses which needs initialWindowMetrics to be passed to the Provider while testing.
Not following the above may lead to an error related to SafeAreaProvider while running yarn test.
To fix the above issue, you can simply pass initialWindowMetrics to NativeBaseProvider in your tests.
Copy
const inset = {
frame: { x: 0, y: 0, width: 0, height: 0 },
insets: { top: 0, left: 0, right: 0, bottom: 0 },
};
<NativeBaseProvider initialWindowMetrics={inset}>
{children}
</NativeBaseProvider>;
Nativebase logo
MadeWithNativeBase