File tree 1 file changed +40
-0
lines changed
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -85,4 +85,44 @@ describe('promiseMiddleware', () => {
85
85
'here you go'
86
86
] ) ;
87
87
} ) ;
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
+ } ) ;
88
128
} ) ;
You can’t perform that action at this time.
0 commit comments