Reactjs 选择class-onChange测试

Reactjs 选择class-onChange测试,reactjs,unit-testing,jestjs,Reactjs,Unit Testing,Jestjs,使用JEST JS和Ezyme编写单元测试。 代码有几个select类,其值设置为不同的状态 例如: 我能够找到以下信息: <Select disabled={disabled} className={showRequired(checkRequired, this.state.AccountStatus, 'value') ? 'account-select req' : 'account-select'} id='custodian-status' value=

使用JEST JS和Ezyme编写单元测试。 代码有几个select类,其值设置为不同的状态

例如: 我能够找到以下信息:

<Select
   disabled={disabled}
   className={showRequired(checkRequired, this.state.AccountStatus, 'value') ? 'account-select req' : 'account-select'}
   id='custodian-status'
   value={this.state.AccountStatus}
   onChange={(e) => {let val = e ? e.value : null; this.setState({AccountStatus: e})}}
   options={this.state.AccountStatusOptions}
/>
错误:方法“props”将在1个节点上运行。取而代之的是4个。正在调用Select 9次,而不是4次

还尝试了以下方法:

wrapper.find('AccountForm').find('Select').find('custodian-status').simulate('change')

错误:方法“模拟”将在1个节点上运行。改为找到0。

find方法可以获取已装载树上呈现的任何元素。模拟需要一个事件类型和一个事件对象。您只需执行以下操作:

wrapper.find('Select').simulate('change', {target { value : 'foo'}})


这正是我以前所拥有的,但我发现了为什么我找不到另一个select我忘记在我的设置状态中添加:type:'add',现在我可以看到9个select节点。实际上,我无法使用simulate找到,这一个对我有效:wrapper.find('AccountForm').find('select').props().onChange({target:{value:'test}}哦!我忘了删除
。查找('AccountForm')
,没有必要链接树。但是我很高兴你能解决你的问题。只是缺少一个setstate,仅此而已。不过还是谢谢你
 wrapper.find('AccountForm').find('Select').props('').onChange(#custodian-status)
wrapper.find('AccountForm').find('Select').find('custodian-status').simulate('change')
wrapper.find('Select').simulate('change', {target { value : 'foo'}})