当前位置:  开发笔记 > 编程语言 > 正文

如何用jest模拟react-native-camera?

如何解决《如何用jest模拟react-native-camera?》经验,为你挑选了1个好方法。



1> locropulento..:

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);

推荐阅读
Chloemw
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有