在Jest-Expo中测试React组件总是失败

时间:2019-07-16 11:57:23

标签: unit-testing react-native npm jestjs expo

我已按照以下教程在Expo上安装Jest。 https://docs.expo.io/versions/latest/guides/testing-with-jest/

按照本教程操作后,我遇到了以下错误:

react-native/jest-preset contained different transformIgnorePatterns than expected
 FAIL  __test__/App.test.js
  ● Test suite failed to run

    Cannot find module '@unimodules/react-native-adapter' from 'setup.js'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:230:17)
      at Object.<anonymous> (node_modules/jest-expo/src/preset/setup.js:218:6)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.348s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

现在,我可以使用npm install @unimodules/react-native-adapter --save-dev安装packace了。 但这会导致以下错误

The Expo SDK requires Expo to run. It appears the native Expo modules are unavailable and this code is not running on Expo. Visit https://docs.expo.io to learn more about developing an Expo project.

      at Object.<anonymous> (node_modules/expo/src/environment/validate.ts:11:9)
      at Object.require (node_modules/expo/build/Expo.js:278:1)

  console.warn node_modules/expo-react-native-adapter/build/NativeModulesProxy.js:43
    The "ExpoNativeModulesProxy" native module is not exported through NativeModules; verify that expo-react-native-adapter's native code is linked properly

  console.warn node_modules/expo-constants/build/Constants.js:4
    No native ExponentConstants module found, are you sure the expo-constants's module is linked properly?

我尝试通过跟踪许多Google链接来解决此问题,我尝试了以下方法:

  • 仅将Jest与Enzyme一起安装。
  • 删除我的所有节点模块,然后重新安装它们。
  • 仅使用纱线

0 个答案:

没有答案
相关问题