@@ -950,6 +950,15 @@ describe('q', function() {
950
950
syncResolve ( deferred , rejectedPromise . then ( ) ) ;
951
951
expect ( log ) . toEqual ( [ 'error(rejected)->reject(rejected)' ] ) ;
952
952
} ) ;
953
+
954
+
955
+ it ( 'should catch exceptions thrown in errback and forward them to derived promises' , function ( ) {
956
+ var rejectedPromise = q . reject ( 'rejected' ) ;
957
+ rejectedPromise . then ( null , error ( 'Broken' , 'catch me!' , true ) ) .
958
+ then ( null , error ( 'Affected' ) )
959
+ mockNextTick . flush ( ) ;
960
+ expect ( log ) . toEqual ( [ 'errorBroken(rejected)->throw(catch me!)' , 'errorAffected(catch me!)->reject(catch me!)' ] ) ;
961
+ } ) ;
953
962
} ) ;
954
963
955
964
@@ -1460,14 +1469,23 @@ describe('q', function() {
1460
1469
deferred = q . defer ( ) ;
1461
1470
} ) ;
1462
1471
1463
-
1472
+
1464
1473
afterEach ( function ( ) {
1465
1474
// Restore the original exception logging mode
1466
1475
mockNextTick . logExceptions = originalLogExceptions ;
1467
1476
} ) ;
1468
1477
1469
1478
1470
1479
it ( 'should still reject the promise, when exception is thrown in success handler, even if exceptionHandler rethrows' , function ( ) {
1480
+ deferred . promise . then ( function ( ) { throw 'reject' ; } ) . then ( null , errorSpy ) ;
1481
+ deferred . resolve ( 'resolve' ) ;
1482
+ mockNextTick . flush ( ) ;
1483
+ expect ( exceptionExceptionSpy ) . toHaveBeenCalled ( ) ;
1484
+ expect ( errorSpy ) . toHaveBeenCalled ( ) ;
1485
+ } ) ;
1486
+
1487
+
1488
+ it ( 'should still reject the promise, when exception is thrown in error handler, even if exceptionHandler rethrows' , function ( ) {
1471
1489
deferred . promise . then ( null , function ( ) { throw 'reject again' ; } ) . then ( null , errorSpy ) ;
1472
1490
deferred . reject ( 'reject' ) ;
1473
1491
mockNextTick . flush ( ) ;
0 commit comments