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

后端 未结 5 768
陌清茗
陌清茗 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条回答
  •  萌比男神i
    2021-02-07 04:44

    This failed for me, too (react-native 0.57.5, jest 23.6.0). I was able to find a solution, but it was totally different (and in my case, a more elegant fix) than here.

    Check out the ticket I filed for more details.

    Essentially, I had to have NativeModules fleshed out by a function passed as the second parameter to jest.mock() and put this is in a script run at the beginning of each test using Jest's setupFiles config option.

提交回复
热议问题