@@ -160,6 +160,23 @@ describe('SpinnerComponent', () => {
160160 }
161161 ) ) ) ;
162162
163+ it ( 'should not show the spinner if the request is filtered by HTTP header' , fakeAsync ( inject (
164+ [ HttpClient , HttpTestingController ] , ( http : HttpClient , httpMock : HttpTestingController ) => {
165+ component . filteredHeaders . push ( 'header-to-filter' ) ;
166+ fixture . detectChanges ( ) ;
167+
168+ http . get ( '/fake' , {
169+ headers : {
170+ 'header-to-filter' : 'value'
171+ }
172+ } ) . subscribe ( ) ;
173+
174+ tick ( ) ;
175+ expect ( component . isSpinnerVisible ) . toBeFalsy ( ) ;
176+ httpMock . expectOne ( '/fake' ) . flush ( { } ) ;
177+ }
178+ ) ) ) ;
179+
163180 it ( 'should take care of query strings in filteredUrlPatterns' , fakeAsync ( inject (
164181 [ HttpClient , HttpTestingController ] , ( http : HttpClient , httpMock : HttpTestingController ) => {
165182 component . filteredUrlPatterns . push ( 'bar' ) ;
@@ -219,6 +236,30 @@ describe('SpinnerComponent', () => {
219236 }
220237 ) ) ) ;
221238
239+ it ( 'should correctly filter by HTTP header with several requests' , fakeAsync ( inject (
240+ [ HttpClient , HttpTestingController ] , ( http : HttpClient , httpMock : HttpTestingController ) => {
241+ component . filteredHeaders . push ( 'My-HeAdER' ) ;
242+ fixture . detectChanges ( ) ;
243+
244+ http . get ( '/12345' , {
245+ headers : {
246+ 'my-header' : 'value'
247+ }
248+ } ) . subscribe ( ) ;
249+ tick ( ) ;
250+ expect ( component . isSpinnerVisible ) . toBeFalsy ( ) ;
251+ httpMock . expectOne ( '/12345' ) . flush ( { } ) ;
252+
253+ http . get ( '/fake' ) . subscribe ( ) ;
254+ tick ( ) ;
255+ expect ( component . isSpinnerVisible ) . toBeTruthy ( ) ;
256+ httpMock . expectOne ( '/fake' ) . flush ( { } ) ;
257+
258+ tick ( ) ;
259+ expect ( component . isSpinnerVisible ) . toBeFalsy ( ) ;
260+ }
261+ ) ) ) ;
262+
222263 it ( 'should throw an error if filteredUrlPatterns is not an array' , ( ) => {
223264 component . filteredUrlPatterns = null ;
224265 expect ( ( ) => fixture . detectChanges ( ) ) . toThrow ( new Error ( '`filteredUrlPatterns` must be an array.' ) ) ;
@@ -229,6 +270,11 @@ describe('SpinnerComponent', () => {
229270 expect ( ( ) => fixture . detectChanges ( ) ) . toThrow ( new Error ( '`filteredMethods` must be an array.' ) ) ;
230271 } ) ;
231272
273+ it ( 'should throw an error if filteredHeaders is not an array' , ( ) => {
274+ component . filteredHeaders = null ;
275+ expect ( ( ) => fixture . detectChanges ( ) ) . toThrow ( new Error ( '`filteredHeaders` must be an array.' ) ) ;
276+ } ) ;
277+
232278 it ( 'should show the spinner even if the component is created after the HTTP request is performed' , fakeAsync ( inject (
233279 [ HttpClient , HttpTestingController ] , ( http : HttpClient , httpMock : HttpTestingController ) => {
234280 http . get ( '/fake' ) . subscribe ( ) ;
0 commit comments