@@ -1500,12 +1500,17 @@ describe('errors', function() {
1500
1500
} ) ;
1501
1501
1502
1502
describe ( 'handling rejections' , function ( ) {
1503
+ var $exceptionHandler ;
1503
1504
var $httpBackend ;
1504
1505
var $resource ;
1505
1506
1506
1507
beforeEach ( module ( 'ngResource' ) ) ;
1508
+ beforeEach ( module ( function ( $exceptionHandlerProvider ) {
1509
+ $exceptionHandlerProvider . mode ( 'log' ) ;
1510
+ } ) ) ;
1507
1511
1508
- beforeEach ( inject ( function ( _$httpBackend_ , _$resource_ ) {
1512
+ beforeEach ( inject ( function ( _$exceptionHandler_ , _$httpBackend_ , _$resource_ ) {
1513
+ $exceptionHandler = _$exceptionHandler_ ;
1509
1514
$httpBackend = _$httpBackend_ ;
1510
1515
$resource = _$resource_ ;
1511
1516
@@ -1524,6 +1529,70 @@ describe('handling rejections', function() {
1524
1529
expect ( errorCb1 ) . toHaveBeenCalledOnce ( ) ;
1525
1530
expect ( errorCb2 ) . toHaveBeenCalledOnce ( ) ;
1526
1531
} ) ;
1532
+
1533
+
1534
+ it ( 'should report a PUR when no error callback or responseError interceptor is provided' ,
1535
+ function ( ) {
1536
+ var CreditCard = $resource ( '/CreditCard' ) ;
1537
+
1538
+ CreditCard . get ( ) ;
1539
+ $httpBackend . flush ( ) ;
1540
+
1541
+ expect ( $exceptionHandler . errors . length ) . toBe ( 1 ) ;
1542
+ expect ( $exceptionHandler . errors [ 0 ] ) . toMatch ( / ^ P o s s i b l y u n h a n d l e d r e j e c t i o n / ) ;
1543
+ }
1544
+ ) ;
1545
+
1546
+
1547
+ it ( 'should not report a PUR when an error callback or responseError interceptor is provided' ,
1548
+ function ( ) {
1549
+ var CreditCard = $resource ( '/CreditCard' , { } , {
1550
+ test1 : {
1551
+ method : 'GET'
1552
+ } ,
1553
+ test2 : {
1554
+ method : 'GET' ,
1555
+ interceptor : { responseError : function ( ) { return { } ; } }
1556
+ }
1557
+ } ) ;
1558
+
1559
+ // With error callback
1560
+ CreditCard . test1 ( noop , noop ) ;
1561
+ $httpBackend . flush ( ) ;
1562
+
1563
+ expect ( $exceptionHandler . errors . length ) . toBe ( 0 ) ;
1564
+
1565
+ // With responseError interceptor
1566
+ CreditCard . test2 ( ) ;
1567
+ $httpBackend . flush ( ) ;
1568
+
1569
+ expect ( $exceptionHandler . errors . length ) . toBe ( 0 ) ;
1570
+
1571
+ // With error callback and responseError interceptor
1572
+ CreditCard . test2 ( noop , noop ) ;
1573
+ $httpBackend . flush ( ) ;
1574
+
1575
+ expect ( $exceptionHandler . errors . length ) . toBe ( 0 ) ;
1576
+ }
1577
+ ) ;
1578
+
1579
+
1580
+ it ( 'should report a PUR when the responseError interceptor returns a rejected promise' ,
1581
+ inject ( function ( $q ) {
1582
+ var CreditCard = $resource ( '/CreditCard' , { } , {
1583
+ test : {
1584
+ method : 'GET' ,
1585
+ interceptor : { responseError : function ( ) { return $q . reject ( { } ) ; } }
1586
+ }
1587
+ } ) ;
1588
+
1589
+ CreditCard . test ( ) ;
1590
+ $httpBackend . flush ( ) ;
1591
+
1592
+ expect ( $exceptionHandler . errors . length ) . toBe ( 1 ) ;
1593
+ expect ( $exceptionHandler . errors [ 0 ] ) . toMatch ( / ^ P o s s i b l y u n h a n d l e d r e j e c t i o n / ) ;
1594
+ } )
1595
+ ) ;
1527
1596
} ) ;
1528
1597
1529
1598
describe ( 'cancelling requests' , function ( ) {
0 commit comments