我的暴徒的简化版本:
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
。
我该如何正确测试此重击?
答案 0 :(得分:0)