Skip to content

Commit f17b0ee

Browse files
authored
Merge pull request #93 from gnom7/tests
Add failing test case
2 parents 5515769 + e8d2495 commit f17b0ee

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/lib/components/ng-http-loader.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ export class NgHttpLoaderComponent implements OnDestroy, OnInit {
4848
const [showSpinner, hideSpinner] = partition((h: boolean) => h)(this.pendingInterceptorService.pendingRequestsStatus$);
4949

5050
this.subscriptions = merge(
51-
showSpinner.pipe(debounce(() => timer(this.debounceDelay))),
51+
merge(showSpinner, hideSpinner).pipe(
52+
switchMap(() => showSpinner.pipe(debounce(() => timer(this.debounceDelay))))
53+
),
5254
showSpinner.pipe(
5355
switchMap(() => hideSpinner.pipe(debounce(() => this.getHidingTimer())))
5456
),

src/test/components/ng-http-loader.component.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,22 @@ describe('NgHttpLoaderComponent', () => {
320320
}
321321
)));
322322

323+
it('should correctly handle the debounce delay for HTTP request finished before spinner should be shown', fakeAsync(inject(
324+
[HttpClient, HttpTestingController], (http: HttpClient, httpMock: HttpTestingController) => {
325+
component.debounceDelay = 2000;
326+
http.get('/fake').subscribe();
327+
328+
// the HTTP request is pending for 1 second now
329+
tick(1000);
330+
expect(component.isSpinnerVisible).toBeFalsy();
331+
332+
// the HTTP request is over, the spinner shouldn't be shown after debounceDelay terminated
333+
httpMock.expectOne('/fake').flush({});
334+
tick(1000);
335+
expect(component.isSpinnerVisible).toBeFalsy();
336+
}
337+
)));
338+
323339
it('should correctly handle the debounce delay for multiple HTTP requests', fakeAsync(inject(
324340
[HttpClient, HttpTestingController], (http: HttpClient, httpMock: HttpTestingController) => {
325341
component.debounceDelay = 2000;

0 commit comments

Comments
 (0)