Redux中调度操作的UnitTest Jest

Redux中调度操作的UnitTest Jest,redux,jestjs,Redux,Jestjs,我不熟悉用笑话来测试Redux 我有以下行动: export const stepDone = (step) => (dispatch) => { dispatch({type: STEP_DONE, payload: step}); } 如何测试此函数 像这样的方法应该会奏效: //Mock the dispatch function with jest's built in mocking functions const mockDispatch = jest.fn()

我不熟悉用笑话来测试Redux

我有以下行动:

export const stepDone = (step) => (dispatch) => {
    dispatch({type: STEP_DONE, payload: step});
}

如何测试此函数

像这样的方法应该会奏效:

//Mock the dispatch function with jest's built in mocking functions
const mockDispatch = jest.fn();
//Call the action
stepDone(999)(mockDispatch)
//Check it was called with the correct arguement
expect(mockDispatch).toHaveBeenCalledWith({type: STEP_DONE, payload: 999})

Redux的神奇之处在于,当您测试操作和还原程序时,您通常只测试纯Javascript,所以它并不特别复杂。

感谢Watson的回答^^。我发现这个决议:)