Skip to content

Commit ce0b676

Browse files
committed
Writing a test case for the feature request described here : #89
1 parent c91b1a2 commit ce0b676

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,43 @@ describe('NgHttpLoaderComponent', () => {
497497
}
498498
)));
499499

500+
it('should correctly handle the minimum spinner duration for multiple HTTP requests ran one after the others', fakeAsync(inject(
501+
[HttpClient, HttpTestingController], (http: HttpClient, httpMock: HttpTestingController) => {
502+
component.minDuration = 2000;
503+
504+
function runQuery(url: string): Observable<any> {
505+
return http.get(url);
506+
}
507+
508+
runQuery('/fake').subscribe();
509+
const firstRequest = httpMock.expectOne('/fake');
510+
511+
tick(1000);
512+
expect(component.isSpinnerVisible).toBeTruthy();
513+
514+
// the first HTTP request is finally over, the spinner is still visible
515+
firstRequest.flush({});
516+
tick();
517+
expect(component.isSpinnerVisible).toBeTruthy();
518+
519+
// 200 ms happen after the first HTTP request has finished, a second HTTP request is launched
520+
tick(200);
521+
expect(component.isSpinnerVisible).toBeTruthy();
522+
523+
runQuery('/fake2').subscribe();
524+
const secondRequest = httpMock.expectOne('/fake2');
525+
526+
// After 900ms, the second http request ends. The spinner should still be visible
527+
tick(700);
528+
secondRequest.flush({});
529+
expect(component.isSpinnerVisible).toBeTruthy();
530+
531+
// 100 ms later, the spinner should be hidden (1000+200+700+100=minDuration)
532+
tick(100);
533+
expect(component.isSpinnerVisible).toBeFalsy();
534+
}
535+
)));
536+
500537
it('should still display the spinner when the minimum duration is inferior to the HTTP request duration', fakeAsync(inject(
501538
[HttpClient, HttpTestingController], (http: HttpClient, httpMock: HttpTestingController) => {
502539
component.minDuration = 1000;

0 commit comments

Comments
 (0)