试图测试以下onChange事件:JEST /酶JS作出反应
it(" Render method : test 1st onChange event :", () => {
baseProps.onChange.mockClear();
wrapper.setState({
localState:{}
});
wrapper.find('#individual-series').simulate('change',{target:{value:""}})
wrapper.update()
wrapper.find('#individual-series').simulate('change', event)
expect(wrapper.state().localState).toEqual('test');
expect(baseProps.addNewSeries).toHaveBeenCalled();
});
我认为这是在计算器上的答案,我想对我的测试申请
const event = Object.assign(jest.fn(), {preventDefault: () => {}})
wrapper.find('#individual-series').simulate('change',event)
但是一旦做到这一点,新的错误弹出其中:它不会“读属性值”分配给该方法
这里是方法
handleChange = (e) => {
if(this.props.currentChartValues.series.map(function(e) { return e.id; }).indexOf(e.target.value) > -1)
{
let options = {
type: toast.TYPE.ERROR,
position: toast.POSITION.TOP_LEFT
}
toast( <div><p>Column already selected.</p><i>Error Code: 001</i></div>, options )
}
else {
e.preventDefault()
let localState = {}
localState[e.target.name] = e.target.value
localState['id'] = this.props.id
if (this.props.defaultData) {
localState = Object.assign({}, this.props.defaultData, localState)
} else {
localState = Object.assign({}, this.state, localState)
}
if (localState.analyzedColumn != null) {
if(localState.axis == null){
localState['axis'] = '0';
}
if(localState.charttype == null){
localState['charttype'] = this.props.currentChartValues.type;
}
对不起,太多的代码行,但目标是让这个onchange事件传递,并了解如何测试时,那里有一个prevetDefault()方法的内部。
谢谢