I'm trying to test that my error-handling action is called when my saga throws an error.
Here's my saga code:
function* createMenu({ values }) {
try {
do some stuff...
} catch (err) {
yield put(displayApiError(err));
}
}
And here's my test code:
const saga = createMenu(mockAction);
const mockError = 'err';
it('calls displayApiError()', () => {
saga.next();
const result = saga.throw(mockError);
expect(result.value).toEqual(put(displayApiError(mockError)));
});
And this is what I see in my jest output:
● createMenu › Failure › calls displayApiError()
expect(received).toEqual(expected)
Expected value to equal:
{"@@redux-saga/IO": true, "PUT": {"action": [Function anonymous], "channel": null}}
Received:
{"@@redux-saga/IO": true, "PUT": {"action": [Function anonymous], "channel": null}}
Difference:
Compared values have no visual difference.
I'm assuming it's the Function anonymous
part that's the issue. I've tried executing both the compared functions themselves and they are both calling displayApiError
in the same way.
So why is the test still failing?
Aucun commentaire:
Enregistrer un commentaire