Root App doesn't maintain its fork anymore, and we at Coorpacademy need to update Mocks as React Native goes further.
A fork of react-native-mock that renders components
- Node.js 16+
- The latest version of react-native
npm i @coorpacademy/react-native-mock-render --save-dev
/* file-that-runs-before-all-of-my-tests.js */
// This will mutate `react-native`'s require cache with `react-native-mock`'s.
require('@coorpacademy/react-native-mock-render/mock')(); // <-- side-effects!!!
to mock optional external libs, use:
require('@coorpacademy/react-native-mock-render/mock')({
externalLibs: [
{
name: 'react-native-lib-with-many-exports',
exports: ['ComponentA', 'ComponentB', 'ComponentC']
},
{
name: 'react-native-lib-with-default-export',
exports: 'ImportName'
},
{
name: 'react-native-modal',
exports: 'Modal'
}
]
});
--> jest mocking https://github.com/facebook/react-native/blob/main/jest/mockComponent.js
Jest doesn't support require.cache
, so the correct way to do the mocking is using jest.mock('react-native', () => require('react-native-mock-render'), {virtual: true})
in your tests setup file.
We wanted to be able deeply render React Native components in our integration tests and already used react-native-mock
.
react-native-mock Core Contributors
- Jake Howard
- Leland Richardson (Original Creator)