@@ -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
@@ -886,6 +886,7 @@ describe("basic usage", function() {
886
886
expect ( cc . url ) . toBe ( '/new-id' ) ;
887
887
} ) ;
888
888
889
+
889
890
it ( 'should pass the same transformed value to success callbacks and to promises' , function ( ) {
890
891
$httpBackend . expect ( 'GET' , '/CreditCard' ) . respond ( 200 , { value : 'original' } ) ;
891
892
@@ -1003,6 +1004,7 @@ describe("basic usage", function() {
1003
1004
} ) ;
1004
1005
} ) ;
1005
1006
1007
+
1006
1008
it ( 'should allow per action response interceptor that gets full response' , function ( ) {
1007
1009
CreditCard = $resource ( '/CreditCard' , { } , {
1008
1010
query : {
@@ -1058,6 +1060,46 @@ describe("basic usage", function() {
1058
1060
expect ( response . status ) . toBe ( 404 ) ;
1059
1061
expect ( response . config ) . toBeDefined ( ) ;
1060
1062
} ) ;
1063
+
1064
+
1065
+ it ( 'should fulfill the promise with the value returned by the responseError interceptor' ,
1066
+ inject ( function ( $q ) {
1067
+ CreditCard = $resource ( '/CreditCard' , { } , {
1068
+ test1 : {
1069
+ method : 'GET' ,
1070
+ interceptor : { responseError : function ( ) { return 'foo' ; } }
1071
+ } ,
1072
+ test2 : {
1073
+ method : 'GET' ,
1074
+ interceptor : { responseError : function ( ) { return $q . resolve ( 'bar' ) ; } }
1075
+ } ,
1076
+ test3 : {
1077
+ method : 'GET' ,
1078
+ interceptor : { responseError : function ( ) { return $q . reject ( 'baz' ) ; } }
1079
+ }
1080
+ } ) ;
1081
+
1082
+ $httpBackend . whenGET ( '/CreditCard' ) . respond ( 404 ) ;
1083
+
1084
+ callback . calls . reset ( ) ;
1085
+ CreditCard . test1 ( ) . $promise . then ( callback ) ;
1086
+ $httpBackend . flush ( ) ;
1087
+
1088
+ expect ( callback ) . toHaveBeenCalledOnceWith ( 'foo' ) ;
1089
+
1090
+ callback . calls . reset ( ) ;
1091
+ CreditCard . test2 ( ) . $promise . then ( callback ) ;
1092
+ $httpBackend . flush ( ) ;
1093
+
1094
+ expect ( callback ) . toHaveBeenCalledOnceWith ( 'bar' ) ;
1095
+
1096
+ callback . calls . reset ( ) ;
1097
+ CreditCard . test3 ( ) . $promise . then ( null , callback ) ;
1098
+ $httpBackend . flush ( ) ;
1099
+
1100
+ expect ( callback ) . toHaveBeenCalledOnceWith ( 'baz' ) ;
1101
+ } )
1102
+ ) ;
1061
1103
} ) ;
1062
1104
1063
1105
@@ -1393,6 +1435,33 @@ describe('errors', function() {
1393
1435
} ) ;
1394
1436
} ) ;
1395
1437
1438
+ describe ( 'handling rejections' , function ( ) {
1439
+ var $httpBackend ;
1440
+ var $resource ;
1441
+
1442
+ beforeEach ( module ( 'ngResource' ) ) ;
1443
+
1444
+ beforeEach ( inject ( function ( _$httpBackend_ , _$resource_ ) {
1445
+ $httpBackend = _$httpBackend_ ;
1446
+ $resource = _$resource_ ;
1447
+
1448
+ $httpBackend . whenGET ( '/CreditCard' ) . respond ( 404 ) ;
1449
+ } ) ) ;
1450
+
1451
+
1452
+ it ( 'should reject the promise even when there is an error callback' , function ( ) {
1453
+ var errorCb1 = jasmine . createSpy ( 'errorCb1' ) ;
1454
+ var errorCb2 = jasmine . createSpy ( 'errorCb2' ) ;
1455
+ var CreditCard = $resource ( '/CreditCard' ) ;
1456
+
1457
+ CreditCard . get ( noop , errorCb1 ) . $promise . catch ( errorCb2 ) ;
1458
+ $httpBackend . flush ( ) ;
1459
+
1460
+ expect ( errorCb1 ) . toHaveBeenCalledOnce ( ) ;
1461
+ expect ( errorCb2 ) . toHaveBeenCalledOnce ( ) ;
1462
+ } ) ;
1463
+ } ) ;
1464
+
1396
1465
describe ( 'cancelling requests' , function ( ) {
1397
1466
var httpSpy ;
1398
1467
var $httpBackend ;
0 commit comments