0

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.

Socratease
  • 191
  • 3
  • 10
  • Did you find a solution for this? I am also seeing that RNCamera is `undefined` in my test. – Sarneet Kaur Oct 03 '18 at 05:07
  • @SarneetKaur I did not, no. We've decided to simply bite the bullet and use RNCamera for both android and ios, and move ahead without jest. – Socratease Oct 04 '18 at 10:04

0 Answers0