How to test a React Native component that imports a custom native module with Jest?

后端 未结 5 635
陌清茗
陌清茗 2021-02-07 04:24

Here is a simple component that I am trying to test using React Native 0.39 and Jest 18:

// index.ios.js

import React, { Component } from \'react\';
import { Ap         


        
5条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-07 05:05

    #__mocks__/react-native-modules
    
    const ReactNative = require('react-native')
    
    ReactNative.NativeModules = {
      Defaults: {
        RU: {
          publicKey: '',
          privateKey: '',
        },
      },
    }
    
    module.exports = ReactNative
    

    and then

    # in test file
    jest.mock('react-native-modules')
    import 'react-native-modules'
    

提交回复
热议问题