So I'm working on setting up some Jest tests for my React Native app, but I'm running into issues when trying to mock react-native-camera.
react-native-camera is currently split into two implementations - RCTCamera, and RNCamera - and I am using both of them. RCTCamera for Android, and RNCamera for iOS.
So my testing suite runs into a big stumble when it hits lines like this:
type: ((Platform.OS === 'android') ? Camera.constants.Type.back : RNCamera.Constants.Type.back),
I've successfully mocked the Camera component and its constants, like so:
import React from 'react';
const constants = constants = {
Aspect: {},
BarCodeType: {},
Type: {},
CaptureMode: {},
CaptureTarget: {},
CaptureQuality: {},
Orientation: {},
FlashMode: {},
TorchMode: {}
};
class Camera extends React.Component {
static constants = constants
render() {
return null;
}
}
Camera.constants = constants;
export default Camera;
And then in the test case doing this:
jest.mock('react-native-camera', () => require.requireActual('../../__mocks__/react-native-camera').default);
But that leaves RNCamera undefined.
I am new to Jest, so I'm still learning. Camera and RNCamera are separate components in separate files in the react-native-camera package. How can I mock them both?
Thank you.