要react-native-camera
在__mocks__
文件夹中修复创建的react组件:
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;
并通过添加以下行修改了测试:
import mockCamera from '../__mocks__/Camera'; jest.mock('react-native-camera', () => mockCamera);