2017-07-10 10 views
0

JestでReduxをユニットテストするのが初めてです。UnitTest Jatch for dispatch Reduxでのアクション

私は、次のアクションがあります。

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

どのように私はこの機能をテストすることができますか?

このような何かが動作するはず

答えて

0

//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をテストしているアクションと減速をテストしているときに、それは特に複雑ではないということです。

+1

回答ありがとうございました^^。私はこの決意を見つけた:) –

関連する問題