Skip to content

Commit eb39583

Browse files
committed
Adjust tests code style
1 parent 159cc01 commit eb39583

File tree

1 file changed

+61
-65
lines changed

1 file changed

+61
-65
lines changed

test/components/spinner/spinner.component.spec.ts

Lines changed: 61 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -98,71 +98,67 @@ describe('SpinnerComponent', () => {
9898
expect(element.style['background-color']).toBe('rgb(255, 0, 0)');
9999
});
100100

101-
it('should show and hide the spinner according to the pending http requests',
102-
inject(
103-
[PendingInterceptorService, HttpClient, HttpTestingController],
104-
(service: PendingInterceptorService, http: HttpClient, httpMock: HttpTestingController) => {
105-
106-
function runQuery(url: string): Observable<any> {
107-
return http.get(url);
108-
}
109-
110-
Observable.forkJoin([runQuery('/fake'), runQuery('/fake2')]).subscribe();
111-
112-
const firstRequest = httpMock.expectOne('/fake');
113-
const secondRequest = httpMock.expectOne('/fake2');
114-
115-
expect(component.isSpinnerVisible).toBeTruthy();
116-
117-
firstRequest.flush({});
118-
expect(component.isSpinnerVisible).toBeTruthy();
119-
120-
secondRequest.flush({});
121-
expect(component.isSpinnerVisible).toBeFalsy();
122-
})
123-
);
124-
125-
it('should hide and show a the spinner for a single http request',
126-
inject(
127-
[PendingInterceptorService, HttpClient, HttpTestingController],
128-
(service: PendingInterceptorService, http: HttpClient, httpMock: HttpTestingController) => {
129-
http.get('/fake').subscribe();
130-
expect(component.isSpinnerVisible).toBeTruthy();
131-
httpMock.expectOne('/fake').flush({});
132-
expect(component.isSpinnerVisible).toBeFalsy();
133-
})
134-
);
135-
136-
it('should not show the spinner if the request is filtered',
137-
inject(
138-
[PendingInterceptorService, HttpClient, HttpTestingController],
139-
(service: PendingInterceptorService, http: HttpClient, httpMock: HttpTestingController) => {
140-
component.filteredUrlPatterns.push('fake');
141-
fixture.detectChanges();
142-
143-
http.get('/fake').subscribe();
144-
expect(component.isSpinnerVisible).toBeFalsy();
145-
httpMock.expectOne('/fake').flush({});
146-
})
147-
);
148-
149-
it('should correctly filter with several requests and one pattern',
150-
inject(
151-
[PendingInterceptorService, HttpClient, HttpTestingController],
152-
(service: PendingInterceptorService, http: HttpClient, httpMock: HttpTestingController) => {
153-
component.filteredUrlPatterns.push('\\d');
154-
fixture.detectChanges();
155-
156-
http.get('/12345').subscribe();
157-
expect(component.isSpinnerVisible).toBeFalsy();
158-
httpMock.expectOne('/12345').flush({});
159-
160-
http.get('/fake').subscribe();
161-
expect(component.isSpinnerVisible).toBeTruthy();
162-
httpMock.expectOne('/fake').flush({});
163-
expect(component.isSpinnerVisible).toBeFalsy();
164-
})
165-
);
101+
it('should show and hide the spinner according to the pending http requests', inject(
102+
[PendingInterceptorService, HttpClient, HttpTestingController],
103+
(service: PendingInterceptorService, http: HttpClient, httpMock: HttpTestingController) => {
104+
105+
function runQuery(url: string): Observable<any> {
106+
return http.get(url);
107+
}
108+
109+
Observable.forkJoin([runQuery('/fake'), runQuery('/fake2')]).subscribe();
110+
111+
const firstRequest = httpMock.expectOne('/fake');
112+
const secondRequest = httpMock.expectOne('/fake2');
113+
114+
expect(component.isSpinnerVisible).toBeTruthy();
115+
116+
firstRequest.flush({});
117+
expect(component.isSpinnerVisible).toBeTruthy();
118+
119+
secondRequest.flush({});
120+
expect(component.isSpinnerVisible).toBeFalsy();
121+
}
122+
));
123+
124+
it('should hide and show a the spinner for a single http request', inject(
125+
[PendingInterceptorService, HttpClient, HttpTestingController],
126+
(service: PendingInterceptorService, http: HttpClient, httpMock: HttpTestingController) => {
127+
http.get('/fake').subscribe();
128+
expect(component.isSpinnerVisible).toBeTruthy();
129+
httpMock.expectOne('/fake').flush({});
130+
expect(component.isSpinnerVisible).toBeFalsy();
131+
}
132+
));
133+
134+
it('should not show the spinner if the request is filtered', inject(
135+
[PendingInterceptorService, HttpClient, HttpTestingController],
136+
(service: PendingInterceptorService, http: HttpClient, httpMock: HttpTestingController) => {
137+
component.filteredUrlPatterns.push('fake');
138+
fixture.detectChanges();
139+
140+
http.get('/fake').subscribe();
141+
expect(component.isSpinnerVisible).toBeFalsy();
142+
httpMock.expectOne('/fake').flush({});
143+
}
144+
));
145+
146+
it('should correctly filter with several requests and one pattern', inject(
147+
[PendingInterceptorService, HttpClient, HttpTestingController],
148+
(service: PendingInterceptorService, http: HttpClient, httpMock: HttpTestingController) => {
149+
component.filteredUrlPatterns.push('\\d');
150+
fixture.detectChanges();
151+
152+
http.get('/12345').subscribe();
153+
expect(component.isSpinnerVisible).toBeFalsy();
154+
httpMock.expectOne('/12345').flush({});
155+
156+
http.get('/fake').subscribe();
157+
expect(component.isSpinnerVisible).toBeTruthy();
158+
httpMock.expectOne('/fake').flush({});
159+
expect(component.isSpinnerVisible).toBeFalsy();
160+
}
161+
));
166162

167163
it('should throw an error if filteredUrlPatterns is not an array', () => {
168164
component.filteredUrlPatterns = null;

0 commit comments

Comments
 (0)