@@ -244,22 +244,35 @@ describe("resource", function() {
244244
245245 describe ( 'failure mode' , function ( ) {
246246 var ERROR_CODE = 500 ,
247- ERROR_RESPONSE = 'Server Error' ;
247+ ERROR_RESPONSE = 'Server Error' ,
248+ errorCB ;
248249
249250 beforeEach ( function ( ) {
250- xhr . expectGET ( '/CreditCard/123' ) . respond ( ERROR_CODE , ERROR_RESPONSE ) ;
251+ errorCB = jasmine . createSpy ( ) ;
251252 } ) ;
252253
253254 it ( 'should report error when non 2xx if error callback is not provided' , function ( ) {
255+ xhr . expectGET ( '/CreditCard/123' ) . respond ( ERROR_CODE , ERROR_RESPONSE ) ;
254256 CreditCard . get ( { id :123 } ) ;
255257 xhr . flush ( ) ;
256258 expect ( $xhrErr ) . toHaveBeenCalled ( ) ;
257259 } ) ;
258260
259261 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 ) ;
261273 xhr . flush ( ) ;
262- expect ( callback ) . toHaveBeenCalledWith ( 500 , ERROR_RESPONSE ) ;
274+ expect ( errorCB ) . toHaveBeenCalledWith ( 500 , ERROR_RESPONSE ) ;
275+ expect ( callback ) . not . toHaveBeenCalled ( ) ;
263276 expect ( $xhrErr ) . not . toHaveBeenCalled ( ) ;
264277 } ) ;
265278 } ) ;
0 commit comments