Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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 方法“;模拟&x201D;将在1个节点上运行。改为找到0。-onClick_Reactjs_Unit Testing_Jestjs - Fatal编程技术网

Reactjs 方法“;模拟&x201D;将在1个节点上运行。改为找到0。-onClick

Reactjs 方法“;模拟&x201D;将在1个节点上运行。改为找到0。-onClick,reactjs,unit-testing,jestjs,Reactjs,Unit Testing,Jestjs,这里有两个使用onClick的事件,我正试图运行一个测试并确保它们通过。我用的是玩笑和酶反应 我错过了什么 事件1: <td> <div className={'add-header-green'} id='test-greenheader'onClick={ ()=>{this.handleChangeOnBlur()} }>+</div> 以下是我的测试文件: 测试1: it('应该在单击事件时调用shandlechangeonflur方法'

这里有两个使用onClick的事件,我正试图运行一个测试并确保它们通过。我用的是玩笑和酶反应

我错过了什么

事件1:

 <td>
 <div className={'add-header-green'}  id='test-greenheader'onClick={ ()=>{this.handleChangeOnBlur()} }>+</div>
以下是我的测试文件: 测试1:

it('应该在单击事件时调用shandlechangeonflur方法',()=>{
//重置这些模拟函数以前可能调用的信息:
baseProps.onClick.mockClear();
wrapper.setProps({});
包装器设置状态({
名称:“”,
值:“”,
localState:true
});
find('#test greenheader').simulate('click',{target:{name:'value'}});
});
测试2:

it('点击按钮时应调用removeParameters函数',()=>{
baseProps.removeParameters.mockClear();
wrapper.setProps({});
wrapper.find(“#test closeimg”).simulate('click');
expect(baseProps.removeParameters).toHaveBeenCalled();
});

您可以发布已完成的组件代码吗?我需要知道你的JSX结构你能发布你完成的组件代码吗?我需要知道你的JSX结构
 <td>
 <img className='remove-header' src={closeImg} id='test-closeimg' onClick={ ()=>{this.props.removeParameters(this.props.id)} } />
 Method “simulate” is meant to be run on 1 node. 0 found instead.