@@ -174,11 +174,12 @@ describe('$httpBackend', function() {
174174 } ) ;
175175
176176 it ( 'should complete the request on timeout' , function ( ) {
177- callback . and . callFake ( function ( status , response , headers , statusText ) {
177+ callback . and . callFake ( function ( status , response , headers , statusText , xhrStatus ) {
178178 expect ( status ) . toBe ( - 1 ) ;
179179 expect ( response ) . toBe ( null ) ;
180180 expect ( headers ) . toBe ( null ) ;
181181 expect ( statusText ) . toBe ( '' ) ;
182+ expect ( xhrStatus ) . toBe ( 'timeout' ) ;
182183 } ) ;
183184 $backend ( 'GET' , '/url' , null , callback , { } ) ;
184185 xhr = MockXhr . $$lastInstance ;
@@ -189,6 +190,60 @@ describe('$httpBackend', function() {
189190 expect ( callback ) . toHaveBeenCalledOnce ( ) ;
190191 } ) ;
191192
193+ it ( 'should complete the request on abort' , function ( ) {
194+ callback . and . callFake ( function ( status , response , headers , statusText , xhrStatus ) {
195+ expect ( status ) . toBe ( - 1 ) ;
196+ expect ( response ) . toBe ( null ) ;
197+ expect ( headers ) . toBe ( null ) ;
198+ expect ( statusText ) . toBe ( '' ) ;
199+ expect ( xhrStatus ) . toBe ( 'abort' ) ;
200+ } ) ;
201+ $backend ( 'GET' , '/url' , null , callback , { } ) ;
202+ xhr = MockXhr . $$lastInstance ;
203+
204+ expect ( callback ) . not . toHaveBeenCalled ( ) ;
205+
206+ xhr . onabort ( ) ;
207+ expect ( callback ) . toHaveBeenCalledOnce ( ) ;
208+ } ) ;
209+
210+ it ( 'should complete the request on error' , function ( ) {
211+ callback . and . callFake ( function ( status , response , headers , statusText , xhrStatus ) {
212+ expect ( status ) . toBe ( - 1 ) ;
213+ expect ( response ) . toBe ( null ) ;
214+ expect ( headers ) . toBe ( null ) ;
215+ expect ( statusText ) . toBe ( '' ) ;
216+ expect ( xhrStatus ) . toBe ( 'error' ) ;
217+ } ) ;
218+ $backend ( 'GET' , '/url' , null , callback , { } ) ;
219+ xhr = MockXhr . $$lastInstance ;
220+
221+ expect ( callback ) . not . toHaveBeenCalled ( ) ;
222+
223+ xhr . onerror ( ) ;
224+ expect ( callback ) . toHaveBeenCalledOnce ( ) ;
225+ } ) ;
226+
227+ it ( 'should complete the request on success' , function ( ) {
228+ callback . and . callFake ( function ( status , response , headers , statusText , xhrStatus ) {
229+ expect ( status ) . toBe ( 200 ) ;
230+ expect ( response ) . toBe ( 'response' ) ;
231+ expect ( headers ) . toBe ( '' ) ;
232+ expect ( statusText ) . toBe ( '' ) ;
233+ expect ( xhrStatus ) . toBe ( 'complete' ) ;
234+ } ) ;
235+ $backend ( 'GET' , '/url' , null , callback , { } ) ;
236+ xhr = MockXhr . $$lastInstance ;
237+
238+ expect ( callback ) . not . toHaveBeenCalled ( ) ;
239+
240+ xhr . statusText = '' ;
241+ xhr . response = 'response' ;
242+ xhr . status = 200 ;
243+ xhr . onload ( ) ;
244+ expect ( callback ) . toHaveBeenCalledOnce ( ) ;
245+ } ) ;
246+
192247 it ( 'should abort request on timeout' , function ( ) {
193248 callback . and . callFake ( function ( status , response ) {
194249 expect ( status ) . toBe ( - 1 ) ;
0 commit comments