@@ -244,22 +244,35 @@ describe("resource", function() {
244
244
245
245
describe ( 'failure mode' , function ( ) {
246
246
var ERROR_CODE = 500 ,
247
- ERROR_RESPONSE = 'Server Error' ;
247
+ ERROR_RESPONSE = 'Server Error' ,
248
+ errorCB ;
248
249
249
250
beforeEach ( function ( ) {
250
- xhr . expectGET ( '/CreditCard/123' ) . respond ( ERROR_CODE , ERROR_RESPONSE ) ;
251
+ errorCB = jasmine . createSpy ( ) ;
251
252
} ) ;
252
253
253
254
it ( 'should report error when non 2xx if error callback is not provided' , function ( ) {
255
+ xhr . expectGET ( '/CreditCard/123' ) . respond ( ERROR_CODE , ERROR_RESPONSE ) ;
254
256
CreditCard . get ( { id :123 } ) ;
255
257
xhr . flush ( ) ;
256
258
expect ( $xhrErr ) . toHaveBeenCalled ( ) ;
257
259
} ) ;
258
260
259
261
it ( 'should call the error callback if provided on non 2xx response' , function ( ) {
260
- CreditCard . get ( { id :123 } , noop , callback ) ;
262
+ xhr . expectGET ( '/CreditCard/123' ) . respond ( ERROR_CODE , ERROR_RESPONSE ) ;
263
+ CreditCard . get ( { id :123 } , callback , errorCB ) ;
264
+ xhr . flush ( ) ;
265
+ expect ( errorCB ) . toHaveBeenCalledWith ( 500 , ERROR_RESPONSE ) ;
266
+ expect ( callback ) . not . toHaveBeenCalled ( ) ;
267
+ expect ( $xhrErr ) . not . toHaveBeenCalled ( ) ;
268
+ } ) ;
269
+
270
+ it ( 'should call the error callback if provided on non 2xx response' , function ( ) {
271
+ xhr . expectGET ( '/CreditCard' ) . respond ( ERROR_CODE , ERROR_RESPONSE ) ;
272
+ CreditCard . get ( callback , errorCB ) ;
261
273
xhr . flush ( ) ;
262
- expect ( callback ) . toHaveBeenCalledWith ( 500 , ERROR_RESPONSE ) ;
274
+ expect ( errorCB ) . toHaveBeenCalledWith ( 500 , ERROR_RESPONSE ) ;
275
+ expect ( callback ) . not . toHaveBeenCalled ( ) ;
263
276
expect ( $xhrErr ) . not . toHaveBeenCalled ( ) ;
264
277
} ) ;
265
278
} ) ;
0 commit comments