如何使用模拟存储正确测试一个称为另一个thunk的thunk

时间:2019-03-06 17:50:28

标签: redux redux-thunk

我的暴徒的简化版本:

fetchUserThunk = () => async (dispatch) => {
dispatch(requestUserStart());
const payload = await getUserAPIrequest();
dispatch(requestUserSuccess(payload));
dispatch(fetchHobbies(payload.userId));

};

fetchHobbiesThunk = (userId) => async (dispatch) => {
    dispatch(requestUserHobbiesStart());
    const payload = await getUserHobbiesAPIrequest(userId);
    dispatch(requestUserHobbiesSuccess(payload));
};

我进行了以下测试:

it('test', async () => {
    const store = mockStore({});
    store.dispatch(fetchUserThunk());

    const expectedActions = [
        requestUserStart(),
        requestUserSuccess(userObj),
        fetchHobbiesThunk(userObj.id)
    ];
    expect(store.getActions()).to.deep.equal(expectedActions);
});

失败,因为第三个动作是requestUserHobbiesStart。 我该如何正确测试此重击?

1 个答案:

答案 0 :(得分:0)