Skip to content

Commit

Permalink
Merge pull request #93 from gnom7/tests
Browse files Browse the repository at this point in the history
Add failing test case
  • Loading branch information
mpalourdio committed Sep 16, 2018
2 parents 5515769 + e8d2495 commit f17b0ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/components/ng-http-loader.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export class NgHttpLoaderComponent implements OnDestroy, OnInit {
const [showSpinner, hideSpinner] = partition((h: boolean) => h)(this.pendingInterceptorService.pendingRequestsStatus$);

this.subscriptions = merge(
showSpinner.pipe(debounce(() => timer(this.debounceDelay))),
merge(showSpinner, hideSpinner).pipe(
switchMap(() => showSpinner.pipe(debounce(() => timer(this.debounceDelay))))
),
showSpinner.pipe(
switchMap(() => hideSpinner.pipe(debounce(() => this.getHidingTimer())))
),
Expand Down
16 changes: 16 additions & 0 deletions src/test/components/ng-http-loader.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,22 @@ describe('NgHttpLoaderComponent', () => {
}
)));

it('should correctly handle the debounce delay for HTTP request finished before spinner should be shown', fakeAsync(inject(
[HttpClient, HttpTestingController], (http: HttpClient, httpMock: HttpTestingController) => {
component.debounceDelay = 2000;
http.get('/fake').subscribe();

// the HTTP request is pending for 1 second now
tick(1000);
expect(component.isSpinnerVisible).toBeFalsy();

// the HTTP request is over, the spinner shouldn't be shown after debounceDelay terminated
httpMock.expectOne('/fake').flush({});
tick(1000);
expect(component.isSpinnerVisible).toBeFalsy();
}
)));

it('should correctly handle the debounce delay for multiple HTTP requests', fakeAsync(inject(
[HttpClient, HttpTestingController], (http: HttpClient, httpMock: HttpTestingController) => {
component.debounceDelay = 2000;
Expand Down

0 comments on commit f17b0ee

Please sign in to comment.