javascript - 为什么要开玩笑这个组件?
问题描述
输入组件必须有道具“名称”。
但 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>
此外,我认为它通过了,因为该玩笑测试实际上只是测试它是否呈现到页面。不是它是否正确渲染。此外,您是否有任何可能基于的默认道具?
推荐阅读
- java - 使用布尔值从用户字符串 java 输入验证
- asp.net-web-api - HttpClient、WebApi 和字符串
- android - Room 数据库的构建错误无法解决
- java - JUnit 测试 POST 到参数化 API
- android - 使用要识别的单词白名单词典加载 Firebase Vision OCR
- mysql - 根据日期和列值在 mysql 中透视数据
- delphi - FormatSettings.ShortDateFormat 与系统区域设置不同
- css - 在 Blazor 中的单击事件上切换 CSS 活动类
- mysql - Mysql显示查询数据和计数
- azure - Azure 自定义策略 KMSI - 密码重置和取消注册重定向到身份验证响应 url