Skip to content

Commit a67052e

Browse files
author
Robert Katic
committed
Add tests for redux-utilities#33.
1 parent 2af37ff commit a67052e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/__tests__/promiseMiddleware-test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,44 @@ describe('promiseMiddleware', () => {
8585
'here you go'
8686
]);
8787
});
88+
89+
it('handles promises that reject with itself', async () => {
90+
// Thenable that synchronously rejects with itself (like jQiery.ajax in jQuery 2)
91+
const selfRejectingSync = {
92+
then(_, eb) {
93+
return Promise.resolve(eb(selfRejectingSync));
94+
}
95+
};
96+
97+
await expect(dispatch({
98+
type: 'ACTION_TYPE',
99+
payload: selfRejectingSync
100+
})).to.eventually.be.rejectedWith(selfRejectingSync);
101+
102+
expect(baseDispatch.calledOnce).to.be.true;
103+
expect(baseDispatch.firstCall.args[0]).to.deep.equal({
104+
type: 'ACTION_TYPE',
105+
payload: selfRejectingSync,
106+
error: true
107+
});
108+
109+
// Promise that rejects with itself (like jQiery.ajax in jQuery 3)
110+
const selfRejectingAsync = new Promise((_, reject) => {
111+
setTimeout(() => {
112+
reject(selfRejectingAsync);
113+
}, 1);
114+
});
115+
116+
await expect(dispatch({
117+
type: 'ACTION_TYPE',
118+
payload: selfRejectingAsync
119+
})).to.eventually.be.rejectedWith(selfRejectingAsync);
120+
121+
expect(baseDispatch.calledTwice).to.be.true;
122+
expect(baseDispatch.secondCall.args[0]).to.deep.equal({
123+
type: 'ACTION_TYPE',
124+
payload: selfRejectingAsync,
125+
error: true
126+
});
127+
});
88128
});

0 commit comments

Comments
 (0)