@@ -64,7 +64,6 @@ describe 'loadingBarInterceptor Service', ->
64
64
$httpBackend .verifyNoOutstandingRequest ()
65
65
$timeout .flush () # loading bar is animated, so flush timeout
66
66
67
-
68
67
it ' should not increment if the response is cached using $http.defaults.cache' , inject (cfpLoadingBar , $cacheFactory ) ->
69
68
$http .defaults .cache = $cacheFactory (' loading-bar' )
70
69
$httpBackend .expectGET (endpoint).respond response
@@ -88,7 +87,6 @@ describe 'loadingBarInterceptor Service', ->
88
87
$httpBackend .verifyNoOutstandingRequest ()
89
88
$timeout .flush () # loading bar is animated, so flush timeout
90
89
91
-
92
90
it ' should not increment if the response is cached' , inject (cfpLoadingBar ) ->
93
91
$httpBackend .expectGET (endpoint).respond response
94
92
$http .get (endpoint, cache : true ).then (data) ->
@@ -160,6 +158,7 @@ describe 'loadingBarInterceptor Service', ->
160
158
expect (cfpLoadingBar .status ()).toBe 1
161
159
$timeout .flush ()
162
160
161
+
163
162
it ' should increment the loading bar when not all requests have been recieved' , inject (cfpLoadingBar ) ->
164
163
$httpBackend .expectGET (endpoint).respond response
165
164
$httpBackend .expectGET (endpoint).respond response
@@ -178,7 +177,6 @@ describe 'loadingBarInterceptor Service', ->
178
177
expect (cfpLoadingBar .status ()).toBe 1
179
178
$timeout .flush () # loading bar is animated, so flush timeout
180
179
181
-
182
180
it ' should count http errors as responses so the loading bar can complete' , inject (cfpLoadingBar ) ->
183
181
# $httpBackend.expectGET(endpoint).respond response
184
182
$httpBackend .expectGET (endpoint).respond 401
@@ -196,8 +194,6 @@ describe 'loadingBarInterceptor Service', ->
196
194
197
195
$timeout .flush ()
198
196
199
-
200
-
201
197
it ' should insert the loadingbar into the DOM when a request is sent' , inject (cfpLoadingBar ) ->
202
198
$httpBackend .expectGET (endpoint).respond response
203
199
$httpBackend .expectGET (endpoint).respond response
@@ -343,7 +339,6 @@ describe 'loadingBarInterceptor Service', ->
343
339
cfpLoadingBar .complete ()
344
340
$timeout .flush ()
345
341
346
-
347
342
it ' should not set the status if the loading bar has not yet been started' , inject (cfpLoadingBar ) ->
348
343
cfpLoadingBar .set (0.5 )
349
344
expect (cfpLoadingBar .status ()).toBe 0
@@ -493,3 +488,61 @@ describe 'LoadingBar only', ->
493
488
494
489
expect (isLoadingBarInjected ($document .find (cfpLoadingBar .parentSelector ))).toBe false
495
490
491
+
492
+ describe ' Interceptor tests' , ->
493
+ provider = $http = $httpBackend = $log = null
494
+ endpoint = ' /service'
495
+ response = {message : ' OK' }
496
+
497
+ describe ' Success response' , ->
498
+
499
+ beforeEach ->
500
+ module ' chieffancypants.loadingBar' , ($httpProvider ) ->
501
+ provider = $httpProvider
502
+ provider .interceptors .push ->
503
+ response : (resp ) ->
504
+ return null
505
+ return
506
+
507
+ inject (_$http_ , _$httpBackend_ , _$log_ ) ->
508
+ $http = _$http_
509
+ $httpBackend = _$httpBackend_
510
+ $log = _$log_
511
+
512
+
513
+ it ' should detect poorly implemented interceptors and warn accordingly' , ->
514
+ expect ($log .error .logs .length ).toBe 0
515
+
516
+ $httpBackend .expectGET (endpoint).respond 204
517
+ $http .get (endpoint)
518
+ $httpBackend .flush ()
519
+
520
+ expect ($log .error .logs .length ).toBe 1
521
+ expect ($log .error .logs ).toContain [' Broken interceptor detected: Config object not supplied in response:\n https://github.com/chieffancypants/angular-loading-bar/pull/50' ]
522
+
523
+ describe ' Error response' , ->
524
+
525
+ beforeEach ->
526
+ module ' chieffancypants.loadingBar' , ($httpProvider ) ->
527
+ provider = $httpProvider
528
+ provider .interceptors .push ($q) ->
529
+ responseError : (resp ) ->
530
+ delete resp .config
531
+ $q .reject (resp);
532
+ return
533
+
534
+ inject (_$http_ , _$httpBackend_ , _$log_ ) ->
535
+ $http = _$http_
536
+ $httpBackend = _$httpBackend_
537
+ $log = _$log_
538
+
539
+
540
+ it ' should detect poorly implemented interceptors and warn accordingly' , ->
541
+ expect ($log .error .logs .length ).toBe 0
542
+
543
+ $httpBackend .expectGET (endpoint).respond 500
544
+ $http .get (endpoint)
545
+ $httpBackend .flush ()
546
+
547
+ expect ($log .error .logs .length ).toBe 1
548
+ expect ($log .error .logs ).toContain [' Broken interceptor detected: Config object not supplied in rejection:\n https://github.com/chieffancypants/angular-loading-bar/pull/50' ]
0 commit comments