如何在已将道具传递给孩子的模拟函数中模拟函数

时间:2019-07-19 06:44:55

标签: reactjs jestjs enzyme

n = int(input("set range:- "))

父组件

I want to mock get Token inside the mocked function in test case by calling from the child component

CHild组件

  onLocationSubmit = async (start, end) => {
        try {
               this.setState({ token: false, isLoader: true, errorMessage: "", routeDetail: {}, path: [] });
      const response = await getToken({ start, end });
      if (response && response.data && response.data.token) {
        this.setState({ token: response.data.token }, () => {
          this.getDirectionPath();
        });
      }
    } catch (error) {
      this.setState({ errorMessage: error.response.data, isLoader: false });
    }
  };

模拟提交功能

const mockSubmit = jest.fn()。mockReturnValue(1);

0 个答案:

没有答案
相关问题