无法读取笑话挂载中未定义的属性'then'

时间:2019-07-20 05:40:11

标签: reactjs jestjs

运行测试时,我尝试使用Mount模拟组件

  TypeError: Cannot read property 'then' of undefined

开玩笑:

beforeEach(() => {
    middleware = applyMiddleware(thunk);    
    store = createStore(combineReducers({ clerks: clerkReducer }), middleware);
    console.log('store is', store);

    wrapper = mount(
      <MemoryRouter>
        <Provider store={store}>
          <ClerksList {...props} dispatch={mockDispatchfn} />
        </Provider>
      </MemoryRouter>,
    );
});

代码:

props.dispatch(fetchClerks()).then(() => {
  setLoading(false);
});

行动电话:

const fetchClerks = (): any => {
  const clerks = store.getState().clerks;
  const params = {
    page: clerks.currentPage,
    perPage: clerks.perPage,
  };
  return (dispatch: Dispatch): Promise<any> =>
    new Promise((resolve, reject) => {
      dispatch(fetchClerksStart());
      http
        .get('/v1/clerks', { params })
        .then((response: any) => {
          if (response) {
            const clerksResponse = {
              currentPage: response.currentPage,
              data: response.clerks,
              isFirstPage: response.isFirstPage,
              isLastPage: response.isLastPage,
              nextPage: response.nextPage,
              perPage: response.perPage,
              prevPage: response.prevPage,
              totalCount: response.totalCount,
              totalPages: response.totalPages,
            };
            dispatch(fetchClerksSuccess(clerksResponse));
          }
          resolve('clerks fetched');
        })
        .catch(error => {
          reject(error.message);
          dispatch(fetchClerksFailure());
        });
    });
};

尽管我已经检查了stackoverflow中的类似问题,但是由于操作应该重新调整,因此已经提到了该问题。虽然我要回电话。我不知道怎么了

0 个答案:

没有答案