【问题标题】:Testing expo-linear-gradient in react native ,throws TypeError: Cannot read property 'includes' of undefined在 react native 中测试 expo-linear-gradient,抛出 TypeError: Cannot read property \'includes\' of undefined
【发布时间】:2022-08-16 20:21:20
【问题描述】:

我的错误:

 TypeError: Cannot read property \'includes\' of undefined

  at requireNativeViewManager (node_modules/expo-modules-core/src/NativeViewManagerAdapter.native.tsx:28:49)
  at Object.<anonymous> (node_modules/expo-linear-gradient/src/NativeLinearGradient.android.tsx:49:34)
  at Object.<anonymous> (node_modules/expo-linear-gradient/src/LinearGradient.tsx:4:1)

我的预设:

 projects: [
{ \"preset\": \"jest-expo/ios\" },
{ \"preset\": \"jest-expo/android\" },
{ \"preset\": \"jest-expo/web\" },

],

零件:

 <LinearGradient
      colors={colorsArray}
      style={{
        ...uikitStyles.progressBar,
        height: heightHandler(height).height,
        backgroundColor: bgColor,
        width: `${newWidth}%`,
      }}
      end={{ x: 1, y: 0 }}
      testID=\"gradient-test\"
    />

Screen Shot of the error

我正在使用 \'@testing-library/react-native\' 编写测试用例,有人可以帮我吗?

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


    【解决方案1】:
    1. 检查 jest-expo 版本和博览会。他们应该匹配。

    2. 检查您的 jest.config.js(原始答案 https://github.com/expo/expo/issues/8527#issuecomment-640103212): 问题是我使用 @testing-library/react-native 作为我的 jest 预设而不是 jest-expo。将 jest-expo 预设与 testing-library 预设一起添加到我的 jest.config.js 设法解决它:

      const expoPreset = require('jest-expo/jest-preset');
      
      module.exports = {
         ...expoPreset,
         preset: "@testing-library/react-native",
      }
      

    【讨论】:

      猜你喜欢
      • 2020-07-30
      • 2017-12-29
      • 2020-11-07
      • 2013-04-22
      • 2021-06-25
      • 1970-01-01
      • 2017-08-19
      • 2017-04-24
      • 2023-03-15
      相关资源
      最近更新 更多