尝试测试以下方法: DeleteseriesbyId。不调用作为功能的道具。
deleteSeriesByID = (id) => {
delete this.state.series[id]
let updateObj = {
0: {
pipe: 'chart',
action: 'transform',
matchValue: 'seriesselected',
series: this.state.series
}
}
this.props.addSeriesList(updateObj)
this.props.updateViewXMLValue(updateObj)
}
道具已经添加,并且渲染正确 这是我尝试测试该方法的方法,想知道是否有更简单的方法 用更少的代码行。使用包装=浅(
it(' Testing Method : Delete Series', () => {
baseProps.addSeriesList.mockClear();
baseProps.updateViewXMLValue.mockClear();
let id = {updateObj :{
0: {
pipe: 'chart',
action: 'transform',
matchValue: 'seriesselected',
series: []
}
}
}
wrapper.setState({
series: [{
test: 'bar',
}],
})
wrapper.instance('deleteAxisByID')
expect(wrapper.instance().state.series).not.toHaveProperty( "test :bar")
expect(baseProps.addSeriesList).toHaveBeenCalledWith({updateObj :"test"});
expect(baseProps.updateViewXMLValue).toHaveReturnedWith(id);
});