相关疑难解决方法(0)

无法读取未定义的属性“方向”,仅测试

我刚刚添加TouchableOpacity到一个组件,应用程序运行良好,但我的测试,使用react-native-testing-library,无法运行:

  ? Test suite failed to run

    TypeError: Cannot read property 'Direction' of undefined

      at Object.Direction (node_modules/react-native-gesture-handler/Directions.js:3:39)
      at Object.<anonymous> (node_modules/react-native-gesture-handler/GestureHandler.js:2:1)
Run Code Online (Sandbox Code Playgroud)

我刚刚删除并重新添加react-native-gesture-handler了纱线,然后运行pod install. 同样,应用程序正在运行,但测试无法运行。

我实际上在使用<Text onPress={() => onOptionPress(opt)} />而不是TouchableOpacity.

成分:

const SelectOptions = ({ field, dismissOverlay, onOptionPress }) => {
  return (
    <Overlay
      isVisible
      overlayStyle={styles.overlay}
      height={"auto"}
      onBackdropPress={dismissOverlay}
    >
      <View>
        {field.options.map((opt, i) => (
          <TouchableOpacity
            style={styles.option}
            key={i}
            onPress={() => onOptionPress(opt)}
          >
            <Text>{opt}</Text>
          </TouchableOpacity>
        ))}
      </View>
    </Overlay>
  );
};
Run Code Online (Sandbox Code Playgroud)

测试:

describe("CardFormView", …
Run Code Online (Sandbox Code Playgroud)

react-native

23
推荐指数
3
解决办法
1万
查看次数

标签 统计

react-native ×1