My action is like this:-
export function requestModel(param) {
return (dispatch) => {
dispatch({
type: 'REQUEST',
loadModel: true,
});
dispatch(getModel(param)).then(response => response.json())
.then(model=>
dispatch(receiveModel(model)))
.catch(() => {
dispatch({
type: MODEL_FAILURE,
loadModel:false,
});
});
};
}
I wrote the test case to cover catch block as :-
it('requestModel() handle sxception...............', (done) => {
const response = { json: () => data };
// call the actual function with stubbed function
try {
dispatchStub.withArgs(getDeviceApiStub).returns(Promise.reject(response));
dispatchStub.withArgs(getDeviceActionStub).returns(Promise.resolve(response));
const returnFunction = modelAction.requestModel(actionParam);
returnFunction(dispatchStub);
done();
sinon.assert.calledWithMatch(dispatchStub, {
type: MODEL_FAILURE,
loadModel:false,
});
done();
} catch (err) {
done(err);
}
});
but the issue is that before catch block of method it is calling the sinon.assert as i wrote above. How to deal with this, i used async await also but same issue is coming, Is there any why so that I can write test cases for the catch block of my action in reactjs?