为什么要开玩笑这个组件?



输入组件必须有props"name".
但是Jest正在通过测试.
这没有意义.
如何修复它?

class Input extends React.Component<
{
errorMassage: string;
label: string;
name: string;
value: number | string;
type: "text" | "number" | "price";
onFocus: () => void;
onChange: (name?: string, e?: MouseEvent) => void;
autoFocus: boolean;
},
{}
......
import React from "react";
import ReactDOM from "react-dom";
import Input from "../Input";
describe("<Input>", () => {
it("renders without crashing", () => {
const div = document.createElement("div");
ReactDOM.render(<Input />, div);
});
});

我认为您需要将道具设置为type InputProps = {...},然后将 React 组件设置为该类型,例如React.Component<InputProps>

此外,我认为它通过了,因为开玩笑的测试实际上只是测试它是否呈现到页面。而不是它是否正确呈现。此外,您是否有任何可能基于自己的默认道具?

最新更新