如何对选择更改事件进行单元测试?

时间:2019-05-05 06:45:04

标签: reactjs unit-testing jestjs

在我的容器类中,我有一个处理选择更改事件的事件:

 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事件?如何使单元测试正常工作?

Link to codesandbox

0 个答案:

没有答案