Skip to content

Commit

Permalink
Reject with action
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Burtchaell committed Jun 25, 2016
1 parent 637808d commit 7feda24
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ export default function promiseMiddleware(config = {}) {
(reason = null) => {
const rejectedAction = getAction(reason, true);
dispatch(rejectedAction);
reject({ reason, action: rejectedAction });

const error = new Error();
error.reason = reason;
error.action = rejectedAction;

reject(error);

return;
}
Expand Down
14 changes: 13 additions & 1 deletion test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ describe('Redux Promise Middleware:', () => {
it('rejected action.type is dispatched', async () => {
const actionDispatched = store.dispatch(nullRejectAction);

await actionDispatched.catch(({ reason, action }) => {
await actionDispatched.catch(({ action, reason }) => {
expect(action).to.eql({
type: `${nullRejectAction.type}_REJECTED`,
error: true
Expand All @@ -339,6 +339,18 @@ describe('Redux Promise Middleware:', () => {
});
});

it('argument is instance of error', async () => {
const actionDispatched = store.dispatch({
type: promiseAction.type,
payload: promiseAction.payload,
meta: metaData
});

await actionDispatched.catch(error => {
expect(error).to.be.instanceOf(Error);
});
});

it('persists meta from original action', async () => {
const actionDispatched = store.dispatch({
type: promiseAction.type,
Expand Down

0 comments on commit 7feda24

Please sign in to comment.