@@ -1103,6 +1103,65 @@ describe('basic usage', function() {
1103
1103
} ) ;
1104
1104
1105
1105
1106
+ describe ( 'success mode' , function ( ) {
1107
+ it ( 'should call the success callback (as 1st argument) on 2xx responses' , function ( ) {
1108
+ var instance , headers , status , statusText ;
1109
+ var successCb = jasmine . createSpy ( 'successCb' ) . and . callFake ( function ( d , h , s , t ) {
1110
+ expect ( d ) . toBe ( instance ) ;
1111
+ expect ( h ( ) ) . toEqual ( jasmine . objectContaining ( headers ) ) ;
1112
+ expect ( s ) . toBe ( status ) ;
1113
+ expect ( t ) . toBe ( statusText ) ;
1114
+ } ) ;
1115
+
1116
+ instance = CreditCard . get ( successCb ) ;
1117
+ headers = { foo : 'bar' } ;
1118
+ status = 200 ;
1119
+ statusText = 'OK' ;
1120
+ $httpBackend . expect ( 'GET' , '/CreditCard' ) . respond ( status , { } , headers , statusText ) ;
1121
+ $httpBackend . flush ( ) ;
1122
+
1123
+ expect ( successCb ) . toHaveBeenCalledOnce ( ) ;
1124
+
1125
+ instance = CreditCard . get ( successCb ) ;
1126
+ headers = { baz : 'qux' } ;
1127
+ status = 299 ;
1128
+ statusText = 'KO' ;
1129
+ $httpBackend . expect ( 'GET' , '/CreditCard' ) . respond ( status , { } , headers , statusText ) ;
1130
+ $httpBackend . flush ( ) ;
1131
+
1132
+ expect ( successCb ) . toHaveBeenCalledTimes ( 2 ) ;
1133
+ } ) ;
1134
+
1135
+
1136
+ it ( 'should call the success callback (as 2nd argument) on 2xx responses' , function ( ) {
1137
+ var instance , headers , status , statusText ;
1138
+ var successCb = jasmine . createSpy ( 'successCb' ) . and . callFake ( function ( d , h , s , t ) {
1139
+ expect ( d ) . toBe ( instance ) ;
1140
+ expect ( h ( ) ) . toEqual ( jasmine . objectContaining ( headers ) ) ;
1141
+ expect ( s ) . toBe ( status ) ;
1142
+ expect ( t ) . toBe ( statusText ) ;
1143
+ } ) ;
1144
+
1145
+ instance = CreditCard . get ( { id : 123 } , successCb ) ;
1146
+ headers = { foo : 'bar' } ;
1147
+ status = 200 ;
1148
+ statusText = 'OK' ;
1149
+ $httpBackend . expect ( 'GET' , '/CreditCard/123' ) . respond ( status , { } , headers , statusText ) ;
1150
+ $httpBackend . flush ( ) ;
1151
+
1152
+ expect ( successCb ) . toHaveBeenCalledOnce ( ) ;
1153
+
1154
+ instance = CreditCard . get ( { id : 456 } , successCb ) ;
1155
+ headers = { baz : 'qux' } ;
1156
+ status = 299 ;
1157
+ statusText = 'KO' ;
1158
+ $httpBackend . expect ( 'GET' , '/CreditCard/456' ) . respond ( status , { } , headers , statusText ) ;
1159
+ $httpBackend . flush ( ) ;
1160
+
1161
+ expect ( successCb ) . toHaveBeenCalledTimes ( 2 ) ;
1162
+ } ) ;
1163
+ } ) ;
1164
+
1106
1165
describe ( 'failure mode' , function ( ) {
1107
1166
var ERROR_CODE = 500 ,
1108
1167
ERROR_RESPONSE = 'Server Error' ,
0 commit comments