redux-actions-assertions icon indicating copy to clipboard operation
redux-actions-assertions copied to clipboard

How to Catch rejected Promise from Action

Open dave-irvine opened this issue 7 years ago • 3 comments

If I have an Action that returns a Promise which may either resolve or reject (redux-form requires this for form submission), how can I write a test that handles the error case? Currently if I reject a Promise the tests are crashing out.

With redux-mock-store you could do this:

store.dispatch(actionA()).catch((err) => { expect(err)...... });

But I can't find a way to do this with this library. Any clues?

dave-irvine avatar May 02 '18 10:05 dave-irvine

@dave-irvine did you figure it out? I am currently facing the same issue.

fernandoabolafio avatar May 22 '18 18:05 fernandoabolafio

No sorry I didn't find a solution

dave-irvine avatar May 22 '18 18:05 dave-irvine

Unfortunately wit the current implementation it expects for all the nested actions to return a resolved promise only: https://github.com/redux-things/redux-actions-assertions-js/blob/78a5fefba99034d38b6454731cc5b167e100e373/src/asserts/utils/unrollActions.js#L13

dmitry-zaets avatar Nov 30 '20 14:11 dmitry-zaets