@@ -30,7 +30,7 @@ describe("basic usage", function() {
30
30
}
31
31
32
32
} ) ;
33
- callback = jasmine . createSpy ( ) ;
33
+ callback = jasmine . createSpy ( 'callback' ) ;
34
34
} ) ) ;
35
35
36
36
@@ -907,6 +907,7 @@ describe("basic usage", function() {
907
907
expect ( cc . url ) . toBe ( '/new-id' ) ;
908
908
} ) ;
909
909
910
+
910
911
it ( 'should pass the same transformed value to success callbacks and to promises' , function ( ) {
911
912
$httpBackend . expect ( 'GET' , '/CreditCard' ) . respond ( 200 , { value : 'original' } ) ;
912
913
@@ -1024,6 +1025,7 @@ describe("basic usage", function() {
1024
1025
} ) ;
1025
1026
} ) ;
1026
1027
1028
+
1027
1029
it ( 'should allow per action response interceptor that gets full response' , function ( ) {
1028
1030
CreditCard = $resource ( '/CreditCard' , { } , {
1029
1031
query : {
@@ -1079,6 +1081,46 @@ describe("basic usage", function() {
1079
1081
expect ( response . status ) . toBe ( 404 ) ;
1080
1082
expect ( response . config ) . toBeDefined ( ) ;
1081
1083
} ) ;
1084
+
1085
+
1086
+ it ( 'should fulfill the promise with the value returned by the responseError interceptor' ,
1087
+ inject ( function ( $q ) {
1088
+ CreditCard = $resource ( '/CreditCard' , { } , {
1089
+ test1 : {
1090
+ method : 'GET' ,
1091
+ interceptor : { responseError : function ( ) { return 'foo' ; } }
1092
+ } ,
1093
+ test2 : {
1094
+ method : 'GET' ,
1095
+ interceptor : { responseError : function ( ) { return $q . resolve ( 'bar' ) ; } }
1096
+ } ,
1097
+ test3 : {
1098
+ method : 'GET' ,
1099
+ interceptor : { responseError : function ( ) { return $q . reject ( 'baz' ) ; } }
1100
+ }
1101
+ } ) ;
1102
+
1103
+ $httpBackend . whenGET ( '/CreditCard' ) . respond ( 404 ) ;
1104
+
1105
+ callback . calls . reset ( ) ;
1106
+ CreditCard . test1 ( ) . $promise . then ( callback ) ;
1107
+ $httpBackend . flush ( ) ;
1108
+
1109
+ expect ( callback ) . toHaveBeenCalledOnceWith ( 'foo' ) ;
1110
+
1111
+ callback . calls . reset ( ) ;
1112
+ CreditCard . test2 ( ) . $promise . then ( callback ) ;
1113
+ $httpBackend . flush ( ) ;
1114
+
1115
+ expect ( callback ) . toHaveBeenCalledOnceWith ( 'bar' ) ;
1116
+
1117
+ callback . calls . reset ( ) ;
1118
+ CreditCard . test3 ( ) . $promise . then ( null , callback ) ;
1119
+ $httpBackend . flush ( ) ;
1120
+
1121
+ expect ( callback ) . toHaveBeenCalledOnceWith ( 'baz' ) ;
1122
+ } )
1123
+ ) ;
1082
1124
} ) ;
1083
1125
1084
1126
@@ -1414,6 +1456,33 @@ describe('errors', function() {
1414
1456
} ) ;
1415
1457
} ) ;
1416
1458
1459
+ describe ( 'handling rejections' , function ( ) {
1460
+ var $httpBackend ;
1461
+ var $resource ;
1462
+
1463
+ beforeEach ( module ( 'ngResource' ) ) ;
1464
+
1465
+ beforeEach ( inject ( function ( _$httpBackend_ , _$resource_ ) {
1466
+ $httpBackend = _$httpBackend_ ;
1467
+ $resource = _$resource_ ;
1468
+
1469
+ $httpBackend . whenGET ( '/CreditCard' ) . respond ( 404 ) ;
1470
+ } ) ) ;
1471
+
1472
+
1473
+ it ( 'should reject the promise even when there is an error callback' , function ( ) {
1474
+ var errorCb1 = jasmine . createSpy ( 'errorCb1' ) ;
1475
+ var errorCb2 = jasmine . createSpy ( 'errorCb2' ) ;
1476
+ var CreditCard = $resource ( '/CreditCard' ) ;
1477
+
1478
+ CreditCard . get ( noop , errorCb1 ) . $promise . catch ( errorCb2 ) ;
1479
+ $httpBackend . flush ( ) ;
1480
+
1481
+ expect ( errorCb1 ) . toHaveBeenCalledOnce ( ) ;
1482
+ expect ( errorCb2 ) . toHaveBeenCalledOnce ( ) ;
1483
+ } ) ;
1484
+ } ) ;
1485
+
1417
1486
describe ( 'cancelling requests' , function ( ) {
1418
1487
var httpSpy ;
1419
1488
var $httpBackend ;
0 commit comments