在我的容器类中,我有一个处理选择更改事件的事件:
handleChangeDebtType = event => {
console.log("handleChangeDebtType value", event.target.value);
this.props.change("debtType", event.target.value);
const newValue = this.updateNewLimit(event.target.value,this.props.currentLimit)
this.props.change("newLimit", newValue);
};
此事件由以下组件触发:
import React from "react";
const DebtType = ({options, handleChangeDebtType}) => {
console.log(options);
return (
<select onChange={handleChangeDebtType}>
{options.map(option => {
return <option value={option.value}>{option.label}</option>;
})}
</select>
);
};
export default DebtType;
这是单元测试:
it('should trigger handleChangeDebtType event',() =>{
const myComp = mount(<MyContainer/>);
let mySelect =myComp.find(DebtType).simulate('click');
expect(mySelect.value).toEqual("0")
})
如何检查触发的handleChangeDebtType
事件?如何使单元测试正常工作?