@@ -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
@@ -1457,6 +1499,33 @@ describe('errors', function() {
1457
1499
} ) ;
1458
1500
} ) ;
1459
1501
1502
+ describe ( 'handling rejections' , function ( ) {
1503
+ var $httpBackend ;
1504
+ var $resource ;
1505
+
1506
+ beforeEach ( module ( 'ngResource' ) ) ;
1507
+
1508
+ beforeEach ( inject ( function ( _$httpBackend_ , _$resource_ ) {
1509
+ $httpBackend = _$httpBackend_ ;
1510
+ $resource = _$resource_ ;
1511
+
1512
+ $httpBackend . whenGET ( '/CreditCard' ) . respond ( 404 ) ;
1513
+ } ) ) ;
1514
+
1515
+
1516
+ it ( 'should reject the promise even when there is an error callback' , function ( ) {
1517
+ var errorCb1 = jasmine . createSpy ( 'errorCb1' ) ;
1518
+ var errorCb2 = jasmine . createSpy ( 'errorCb2' ) ;
1519
+ var CreditCard = $resource ( '/CreditCard' ) ;
1520
+
1521
+ CreditCard . get ( noop , errorCb1 ) . $promise . catch ( errorCb2 ) ;
1522
+ $httpBackend . flush ( ) ;
1523
+
1524
+ expect ( errorCb1 ) . toHaveBeenCalledOnce ( ) ;
1525
+ expect ( errorCb2 ) . toHaveBeenCalledOnce ( ) ;
1526
+ } ) ;
1527
+ } ) ;
1528
+
1460
1529
describe ( 'cancelling requests' , function ( ) {
1461
1530
var httpSpy ;
1462
1531
var $httpBackend ;
0 commit comments