Jest:如何模拟一个 redux thunk 调用另一个 thunk?

adi*_*iti 5 javascript unit-testing reactjs jestjs redux

我有以下 redux thunk:

function thunkOne() {
    return dispatch => {
        callToApi().then(() => {
            dispatch(someNonThunkAction());
            dispatch(thunkTwo());
        });
    }
}

function thunkTwo() {
   return dispatch => {
      anotherCallToApi.then(dispatch(someOtherAction()));
   }
}
Run Code Online (Sandbox Code Playgroud)

我只想测试thunkOne和模拟,thunkTwo以便在我测试时它不会被执行thunkOne

我试图这样做,但它不起作用:

import * as someActions from './actions';

it ('thunkOne should dispatch someNonThunkAction and thunkTwo', () => {
    someActions.thunkTwo = jest.fn();
    const expectedActions = [
            { type: SOME_NON_THUNK_ACTION, data: {} }
        ],
        store = mockStore(initialState);

    store.dispatch(someActions.thunkOne()).then(() => {
        expect(store.getActions()).toEqual(expectedActions);
        expect(someActions.thunkTwo).toHaveBeenCalled();
    });

    someActions.thunkTwo.mockRestore();
});
Run Code Online (Sandbox Code Playgroud)

运行此测试时出现以下错误:

[错误] 操作必须是普通对象。使用自定义中间件进行异步操作。

我如何只模拟thunkTwo和测试thunkOne