@@ -1124,6 +1124,65 @@ describe('basic usage', function() {
1124
1124
} ) ;
1125
1125
1126
1126
1127
+ describe ( 'success mode' , function ( ) {
1128
+ it ( 'should call the success callback (as 1st argument) on 2xx responses' , function ( ) {
1129
+ var instance , headers , status , statusText ;
1130
+ var successCb = jasmine . createSpy ( 'successCb' ) . and . callFake ( function ( d , h , s , t ) {
1131
+ expect ( d ) . toBe ( instance ) ;
1132
+ expect ( h ( ) ) . toEqual ( jasmine . objectContaining ( headers ) ) ;
1133
+ expect ( s ) . toBe ( status ) ;
1134
+ expect ( t ) . toBe ( statusText ) ;
1135
+ } ) ;
1136
+
1137
+ instance = CreditCard . get ( successCb ) ;
1138
+ headers = { foo : 'bar' } ;
1139
+ status = 200 ;
1140
+ statusText = 'OK' ;
1141
+ $httpBackend . expect ( 'GET' , '/CreditCard' ) . respond ( status , { } , headers , statusText ) ;
1142
+ $httpBackend . flush ( ) ;
1143
+
1144
+ expect ( successCb ) . toHaveBeenCalledOnce ( ) ;
1145
+
1146
+ instance = CreditCard . get ( successCb ) ;
1147
+ headers = { baz : 'qux' } ;
1148
+ status = 299 ;
1149
+ statusText = 'KO' ;
1150
+ $httpBackend . expect ( 'GET' , '/CreditCard' ) . respond ( status , { } , headers , statusText ) ;
1151
+ $httpBackend . flush ( ) ;
1152
+
1153
+ expect ( successCb ) . toHaveBeenCalledTimes ( 2 ) ;
1154
+ } ) ;
1155
+
1156
+
1157
+ it ( 'should call the success callback (as 2nd argument) on 2xx responses' , function ( ) {
1158
+ var instance , headers , status , statusText ;
1159
+ var successCb = jasmine . createSpy ( 'successCb' ) . and . callFake ( function ( d , h , s , t ) {
1160
+ expect ( d ) . toBe ( instance ) ;
1161
+ expect ( h ( ) ) . toEqual ( jasmine . objectContaining ( headers ) ) ;
1162
+ expect ( s ) . toBe ( status ) ;
1163
+ expect ( t ) . toBe ( statusText ) ;
1164
+ } ) ;
1165
+
1166
+ instance = CreditCard . get ( { id : 123 } , successCb ) ;
1167
+ headers = { foo : 'bar' } ;
1168
+ status = 200 ;
1169
+ statusText = 'OK' ;
1170
+ $httpBackend . expect ( 'GET' , '/CreditCard/123' ) . respond ( status , { } , headers , statusText ) ;
1171
+ $httpBackend . flush ( ) ;
1172
+
1173
+ expect ( successCb ) . toHaveBeenCalledOnce ( ) ;
1174
+
1175
+ instance = CreditCard . get ( { id : 456 } , successCb ) ;
1176
+ headers = { baz : 'qux' } ;
1177
+ status = 299 ;
1178
+ statusText = 'KO' ;
1179
+ $httpBackend . expect ( 'GET' , '/CreditCard/456' ) . respond ( status , { } , headers , statusText ) ;
1180
+ $httpBackend . flush ( ) ;
1181
+
1182
+ expect ( successCb ) . toHaveBeenCalledTimes ( 2 ) ;
1183
+ } ) ;
1184
+ } ) ;
1185
+
1127
1186
describe ( 'failure mode' , function ( ) {
1128
1187
var ERROR_CODE = 500 ,
1129
1188
ERROR_RESPONSE = 'Server Error' ,
0 commit comments