所以我有一个显示一些文本字段的组件。一个输入,一个选择,根据用户在该选择上使用的输入,(选择的值)显示或不显示第三个。
我尝试使用 React-Test-Renderer 仅测试第一个输入字段,但出现以下错误:预期 1 但发现 2 个节点类型为“未定义”的实例
这是输入字段代码:
<div>
<div className="container">
<h3 className="h3">Info</h3>
<div className="row">
<div className="col">
<label htmlFor="test">test:</label>
<input
id="myID"
value={aPropThatIsAnEmptyString}
type="text"
className={`form-control form-control-sm ${style.fieldsGap}`}
onChange={e => setTest(e.target.value)}
placeholder="test"
/>
</div>
<div className="col">
<label htmlFor="ddlType">test2:</label>
<select
id="SelectId"
Run Code Online (Sandbox Code Playgroud)
这是我的测试代码:
it("test input field", () => {
const newProps = {
something: initialState,
dispatch: reducer
};
const component = TestRenderer.create(
<ContextBR.Provider value={{ ...newProps }}>
<ComponentWithTheFields/>
</ContextBR.Provider>
);
const rootInstance = component.root;
console.log(rootInstance);
const inputField = rootInstance.findByType("input");
inputField.props.onChange({ target: { value: "" …Run Code Online (Sandbox Code Playgroud)