等待响应-JS单元测试

时间:2019-07-18 18:07:28

标签: reactjs async-await enzyme

运行单元测试,并且能够测试click和onchange事件。不太确定如何测试以下内容:

async patchCustodian() {
const { user, services, FirmId, custodianToEdit } = this.props;      
let CustodianBody = { 
  FirmID: this.props.FirmId,
  Name: this.state.Name,
   }
let response = await Models.patchCustodian({
  user,
  services,
  firmId: FirmId,
  body: CustodianBody,
  id: custodianToEdit
})
if(!response.error) {
  return true;
} else {
  return false;
 }        
}

这是我到目前为止要测试的:

it('Test patchCustodian function ',async() => {
 wrapper.setProps({
 //list of props
   })
 wrapper.find('ClassTest'').setState({
  //list of states
   })

    custodianStatusRequestedId:"idvalue"
    });
wrapper.update();
await expect(wrapper.find('ClassTest').instance().patchCustodian()).toBeDefined()

});

使用笑话和酶。目标:能够使用正确的道具和状态正确测试该功能,并确保代码增加其覆盖范围

0 个答案:

没有答案