小编Alo*_*lon的帖子

反应本机无法找到具有 testID 的元素

我收到此错误:

Unable to find an element with the testID of: input-text

输入.js

import React from "react";
import { View, StyleSheet } from "react-native";
import { Text, TextInput } from "react-native-paper";

const Input = (props) => {
  return (
    <View>
      <TextInput
        name={props.name}
        keyboardType={props.keyboardType}
        value={props.value}
        label={props.label}
        mode="outlined"
        onChange={(newVal) => props.onChange(props.name, newVal)}
        required={props.required}
        data-testid="input-text"
      />
      <Text>{props.errors}</Text>
    </View>
  );
};

export default Input;
Run Code Online (Sandbox Code Playgroud)

输入 test.js

import React from "react";
import { Input } from "../components/common";

import { render, fireEvent } from "@testing-library/react-native"; …
Run Code Online (Sandbox Code Playgroud)

reactjs jestjs react-native react-testing-library

5
推荐指数
2
解决办法
4295
查看次数