【问题标题】:Can anyone help me to write test case for the following action?谁能帮我为以下操作编写测试用例?
【发布时间】:2022-10-20 22:46:26
【问题描述】:
export const fetchP2pPriceConstraints = () => {
  return async (dispatch, getState) => {
    const response = await api.fetchP2pConstraints();
    const apiResponse = await response.data;
    if (response.status === 200 && apiResponse.code === 200) {
      dispatch({
        type: PRICE_CONSTRAINTS,
        payload: {
          priceConstraints: apiResponse.result,
        },
      });
      return Promise.resolve(apiResponse);
    }
    return Promise.reject(response);
  };
};

这是我需要在我的测试用例中涵盖的 redux 操作,我尝试了不同的方法,但没有一个效果这么好。

【问题讨论】:

    标签: javascript react-native unit-testing react-redux


    【解决方案1】:
    it('test p2p price constraints action', () => {
        store.dispatch(fetchP2pPriceConstraints()).then(() => {
          let expectedActions = [
            {
              type: PRICE_CONSTRAINTS,
              payload: {
                priceConstraints: {},
              },
            },
          ];
    
          expect(store.getActions()).toEqual(expectedActions);
        });
      });
    

    我试过这个,它正在工作,但没有覆盖所有线路。

    【讨论】:

      猜你喜欢
      • 2021-12-08
      • 1970-01-01
      • 1970-01-01
      • 2010-12-16
      • 2021-08-26
      • 1970-01-01
      • 2021-06-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多