Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React jest酶模拟更改抛出警告:受控更改为非受控更改_Reactjs_Jestjs_Enzyme - Fatal编程技术网

Reactjs React jest酶模拟更改抛出警告:受控更改为非受控更改

Reactjs React jest酶模拟更改抛出警告:受控更改为非受控更改,reactjs,jestjs,enzyme,Reactjs,Jestjs,Enzyme,我正在使用jest Ezyme 7.0开发React 16.8,并面临一个问题,即测试用例正在通过,但发出警告: A component is changing an uncontrolled input of type text to be controlled. 我的输入标签如下所示: <input type=“text” value={myValue} onChange={(event) => handleChange(event)} /> <input typ

我正在使用jest Ezyme 7.0开发React 16.8,并面临一个问题,即测试用例正在通过,但发出警告:

A component is changing an uncontrolled input of type text to be controlled.
我的输入标签如下所示:

<input type=“text” value={myValue} onChange={(event) => handleChange(event)} />
<input type=“text” value={myValue || “”} onChange={(event) => handleChange(event)} />
handleChange(事件)}/>
我的测试用例模拟事件如下:

const wrapper = mount(<MyComponent />);
wrapper.find(“#myInput”).simulate(“change”, {target: {value: “asdf”}});
const wrapper=mount();
find(“#myInput”).simulate(“更改”,{target:{value:{asdf}});

我花了很多时间在谷歌上搜索,并通过如下方式为我的输入指定一个默认值来解决此问题:

<input type=“text” value={myValue} onChange={(event) => handleChange(event)} />
<input type=“text” value={myValue || “”} onChange={(event) => handleChange(event)} />
handleChange(事件)}/>
这对我很有效