@@ -55,11 +55,7 @@ class AssertionError extends Error {
55
55
// Reserved for power-assert statements
56
56
this . statements = [ ] ;
57
57
58
- if ( options . savedError ) {
59
- this . savedError = options . savedError ;
60
- } else {
61
- this . savedError = getErrorWithLongStackTrace ( ) ;
62
- }
58
+ this . savedError = options . savedError ? options . savedError : getErrorWithLongStackTrace ( ) ;
63
59
}
64
60
}
65
61
exports . AssertionError = AssertionError ;
@@ -502,7 +498,7 @@ class Assertions {
502
498
retval = fn ( ) ;
503
499
if ( isPromise ( retval ) ) {
504
500
// Here isPromise() checks if something is "promise like". Cast to an actual promise.
505
- Promise . resolve ( retval ) . catch ( noop ) ;
501
+ Promise . resolve ( retval ) . catch ( noop ) ; // eslint-disable-line promise/prefer-await-to-then
506
502
fail ( new AssertionError ( {
507
503
assertion : 'throws' ,
508
504
message,
@@ -562,7 +558,7 @@ class Assertions {
562
558
return Promise . resolve ( ) ;
563
559
}
564
560
565
- const handlePromise = ( promise , wasReturned ) => {
561
+ const handlePromise = async ( promise , wasReturned ) => {
566
562
// Create an error object to record the stack before it gets lost in the promise chain.
567
563
const savedError = getErrorWithLongStackTrace ( ) ;
568
564
// Handle "promise like" objects by casting to a real Promise.
@@ -586,8 +582,11 @@ class Assertions {
586
582
} ) ;
587
583
588
584
pending ( intermediate ) ;
589
- // Don't reject the returned promise, even if the assertion fails.
590
- return intermediate . catch ( noop ) ;
585
+ try {
586
+ return await intermediate ;
587
+ } catch {
588
+ // Don't reject the returned promise, even if the assertion fails.
589
+ }
591
590
} ;
592
591
593
592
if ( isPromise ( thrower ) ) {
@@ -669,7 +668,7 @@ class Assertions {
669
668
return Promise . resolve ( ) ;
670
669
}
671
670
672
- const handlePromise = ( promise , wasReturned ) => {
671
+ const handlePromise = async ( promise , wasReturned ) => {
673
672
// Create an error object to record the stack before it gets lost in the promise chain.
674
673
const savedError = getErrorWithLongStackTrace ( ) ;
675
674
// Handle "promise like" objects by casting to a real Promise.
@@ -682,8 +681,12 @@ class Assertions {
682
681
} ) ;
683
682
} ) ;
684
683
pending ( intermediate ) ;
685
- // Don't reject the returned promise, even if the assertion fails.
686
- return intermediate . catch ( noop ) ;
684
+
685
+ try {
686
+ return await intermediate ;
687
+ } catch {
688
+ // Don't reject the returned promise, even if the assertion fails.
689
+ }
687
690
} ;
688
691
689
692
if ( isPromise ( nonThrower ) ) {
0 commit comments