使用Jest酶测试吐司

时间:2019-04-10 12:00:37

标签: reactjs jestjs

运行测试,可以确定click和onChange事件。 尝试测试一种方法,但不确定如何测试吐司/选项

这是方法:

fireUserDelete = (user) =>{
  fetch(`${this.props.services.Dashboard.URL}/USER?id=${user.UserId}`, {
      headers: {
          'Content-Type': 'application/json',
          'Ocp-Apim-Subscription-Key': this.props.services.Dashboard.subscription_key,
      },
      method: 'DELETE',
      credentials: 'include',
    }).then(res => {
      if (res.ok){
         for(var i=0; i<user.Roles.length; i++){
                fetch(`${this.props.services.Dashboard.URL}/USER_FIRM_LINK?id=${user.Roles[i].UserFirmLinkId}`, {
                headers: {
                    'Content-Type': 'application/json',
                    'Ocp-Apim-Subscription-Key': this.props.services.Dashboard.subscription_key,
                    },
                    method: 'DELETE',
                    credentials: 'include',
                })
            }

          let options = {
               type: toast.TYPE.SUCCESS,
               position: toast.POSITION.TOP_LEFT
            }
            toast( <div>User Removed Successfully</div>, options)
        }
        else{
            let options = {
                type: toast.TYPE.ERROR,
                position: toast.POSITION.TOP_LEFT
            }
            toast( <div>Failed To Remove User</div>, options)
        }
    })
}

这里是我通常如何设置考试的方式。使用浅 用于React Js的Enzyme Jest 我可以添加些什么来确保上面的整个文件都经过测试,尤其是吐司 谢谢

it('Test fireUserDelete method',() => {
    wrapper.setProps({
     services:{
       Dashboard:{
          URL:"",
          subscription_key:{},
         },
         },
       })
      wrapper.setState({     });
      wrapper.update();
      expect(wrapper.instance().fireUserDelete({target:{value:'test'}})).toEqual();

   });

0 个答案:

没有答案