Skip to content

Commit

Permalink
Add tests for redux-utilities#33.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Katic committed Jul 31, 2016
1 parent 2af37ff commit a67052e
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/__tests__/promiseMiddleware-test.js
Expand Up @@ -85,4 +85,44 @@ describe('promiseMiddleware', () => {
'here you go'
]);
});

it('handles promises that reject with itself', async () => {
// Thenable that synchronously rejects with itself (like jQiery.ajax in jQuery 2)
const selfRejectingSync = {
then(_, eb) {
return Promise.resolve(eb(selfRejectingSync));
}
};

await expect(dispatch({
type: 'ACTION_TYPE',
payload: selfRejectingSync
})).to.eventually.be.rejectedWith(selfRejectingSync);

expect(baseDispatch.calledOnce).to.be.true;
expect(baseDispatch.firstCall.args[0]).to.deep.equal({
type: 'ACTION_TYPE',
payload: selfRejectingSync,
error: true
});

// Promise that rejects with itself (like jQiery.ajax in jQuery 3)
const selfRejectingAsync = new Promise((_, reject) => {
setTimeout(() => {
reject(selfRejectingAsync);
}, 1);
});

await expect(dispatch({
type: 'ACTION_TYPE',
payload: selfRejectingAsync
})).to.eventually.be.rejectedWith(selfRejectingAsync);

expect(baseDispatch.calledTwice).to.be.true;
expect(baseDispatch.secondCall.args[0]).to.deep.equal({
type: 'ACTION_TYPE',
payload: selfRejectingAsync,
error: true
});
});
});

0 comments on commit a67052e

Please sign in to comment.