File tree 2 files changed +26
-2
lines changed 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -182,13 +182,14 @@ function wrapAssertions(callbacks) {
182
182
coreAssertThrowsErrorArg = err ;
183
183
}
184
184
185
+ let maybePromise ;
185
186
const test = ( fn , stack ) => {
186
187
let actual ;
187
188
let threw = false ;
188
189
try {
189
190
coreAssert . throws ( ( ) => {
190
191
try {
191
- fn ( ) ;
192
+ maybePromise = fn ( ) ;
192
193
} catch ( err ) {
193
194
actual = err ;
194
195
threw = true ;
@@ -208,7 +209,7 @@ function wrapAssertions(callbacks) {
208
209
}
209
210
} ;
210
211
211
- if ( promise ) {
212
+ const handlePromise = promise => {
212
213
// Record stack before it gets lost in the promise chain.
213
214
const stack = getStack ( ) ;
214
215
const intermediate = promise . then ( value => {
@@ -222,13 +223,25 @@ function wrapAssertions(callbacks) {
222
223
pending ( this , intermediate ) ;
223
224
// Don't reject the returned promise, even if the assertion fails.
224
225
return intermediate . catch ( noop ) ;
226
+ } ;
227
+
228
+ if ( promise ) {
229
+ return handlePromise . call ( this , promise ) ;
225
230
}
226
231
227
232
try {
228
233
const retval = test ( fn ) ;
229
234
pass ( this ) ;
230
235
return retval ;
231
236
} catch ( err ) {
237
+ if ( maybePromise ) {
238
+ if ( isPromise ( maybePromise ) ) {
239
+ return handlePromise . call ( this , maybePromise ) ;
240
+ }
241
+ if ( isObservable ( maybePromise ) ) {
242
+ return handlePromise . call ( this , observableToPromise ( maybePromise ) ) ;
243
+ }
244
+ }
232
245
fail ( this , err ) ;
233
246
}
234
247
} ,
Original file line number Diff line number Diff line change @@ -678,6 +678,17 @@ test('.throws() returns the rejection reason of promise', t => {
678
678
} ) ;
679
679
} ) ;
680
680
681
+ test ( '.throws() returns the rejection reason of function that return rejected `Promise`' , t => {
682
+ const expected = new Error ( ) ;
683
+
684
+ return assertions . throws ( ( ) => {
685
+ return Promise . reject ( expected ) ;
686
+ } ) . then ( actual => {
687
+ t . is ( actual , expected ) ;
688
+ t . end ( ) ;
689
+ } ) ;
690
+ } ) ;
691
+
681
692
test ( '.throws() fails if passed a bad value' , t => {
682
693
failsWith ( t , ( ) => {
683
694
assertions . throws ( 'not a function' ) ;
You can’t perform that action at this time.
0 commit comments