ฉันไม่สามารถทดสอบ onClick สำหรับรหัสต่อไปนี้ด้านล่าง ฉันได้รับข้อผิดพลาดต่อไปนี้:
Method “simulate” is meant to be run on 1 node. 0 found instead.
รหัสส่วนประกอบของฉันมีลักษณะดังนี้:
constructor (props) {
super(props)
this.state = INITIAL_STATE;
}
handleQuickFilter = (type) => {
this.setState({
quickFilterObj: {...this.state.quickFilterObj, [type]: {...this.state.quickFilterObj[type], checked: !this.state.quickFilterObj[type].checked}}
}, () => {
let filter = this.buildFilter();
filter ?
linker.UniversalGrid('Counterparty.Loa.Enrollment', '', `{form_filter}=$filter=(${filter}),{grid_selectable}=1,{can_add}=1`)
:
linker.UniversalGrid('Counterparty.Loa.Enrollment', '', `{form_filter}='',{grid_selectable}=1,{can_add}=1`)
})
}
render () {
return(
<div className='enrollment-grid-wrapper'>
<div className='quick-filter-div'>
<button className={this.state.quickFilterObj['New'] && this.state.quickFilterObj['New'].checked ? 'checked quick-filter' : 'unchecked quick-filter'}
id = 'testnew'
onClick={() => {this.handleQuickFilter('New')}}
>
New {this.state.quickFilterObj['New'] && this.state.quickFilterObj['New'].count !== undefined ? `(${this.state.quickFilterObj['New'].count})` : null}
</button>
<button className={this.state.quickFilterObj['Sent'] && this.state.quickFilterObj['Sent'].checked ? 'checked quick-filter' : 'unchecked quick-filter'}
onClick={()=>{this.handleQuickFilter('Sent')}}
>
Sent {this.state.quickFilterObj['Sent'] && this.state.quickFilterObj['Sent'].count !== undefined ? `(${this.state.quickFilterObj['Sent'].count})` : null}
</button>
)
}
ฉันได้ลองทำสิ่งต่อไปนี้โดยใช้ Jest / enzyme:
it("should HandlequickFilter with button click", () => {
wrapper.setProps({});
wrapper.setState({quickFilterObj:"test"});
wrapper.find('.quick-filter-div').at(0).simulate("click");
expect(wrapper.state().quickFilterObj.New.checked).toEqual(true);
});
ฉันจะทำให้การทดสอบต่อไปนี้ผ่านได้อย่างไร
quick-filter-div
แต่คลาสจะถูกเปลี่ยนชื่อเป็นคลาสที่มีสตริงเพิ่มเติมต่อท้าย - person Alvin S. Lee   schedule 21.02.2019