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

后端 未结 5 624
陌清茗
陌清茗 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 04:44

    Jest is a JavaScript testing tool, it won't run code that you have written in Objective C/Swift/Java in a native module. You can mock the functionality of a native module so that you can call it from JavaScript by the approach you linked to. eg.

    jest.mock('NetInfo', () => {
      return {
        isConnected: {
          fetch: () => {
            return new Promise((accept, resolve) => {
              accept(true);
            })
          }
        }
      }
    });
    

提交回复
热议问题