1010import { HttpClient } from '@angular/common/http' ;
1111import { HttpClientTestingModule , HttpTestingController } from '@angular/common/http/testing' ;
1212import { ChangeDetectionStrategy , Component } from '@angular/core' ;
13- import { async , ComponentFixture , fakeAsync , inject , TestBed , tick } from '@angular/core/testing' ;
13+ import { async , ComponentFixture , fakeAsync , TestBed , tick } from '@angular/core/testing' ;
1414import { By } from '@angular/platform-browser' ;
1515import { NgHttpLoaderModule } from '../../lib/ng-http-loader.module' ;
1616
@@ -24,6 +24,8 @@ export class HostComponent {
2424describe ( 'NgHttpLoaderComponent OnPush' , ( ) => {
2525 let component : HostComponent ;
2626 let fixture : ComponentFixture < HostComponent > ;
27+ let http : HttpClient ;
28+ let httpMock : HttpTestingController ;
2729
2830 beforeEach ( async ( ( ) => {
2931 TestBed . configureTestingModule ( {
@@ -36,27 +38,27 @@ describe('NgHttpLoaderComponent OnPush', () => {
3638 beforeEach ( ( ) => {
3739 fixture = TestBed . createComponent ( HostComponent ) ;
3840 component = fixture . componentInstance ;
41+ http = TestBed . get ( HttpClient ) ;
42+ httpMock = TestBed . get ( HttpTestingController ) ;
3943 } ) ;
4044
41- it ( 'should work as expected when the host component has ChangeDetectionStrategy.OnPush' , fakeAsync ( inject (
42- [ HttpClient , HttpTestingController ] , ( http : HttpClient , httpMock : HttpTestingController ) => {
43- http . get ( '/fake' ) . subscribe ( ) ;
44- tick ( ) ;
45- fixture . detectChanges ( ) ;
46- let spinner = fixture
47- . debugElement
48- . query ( By . css ( '#spinner' ) )
49- . nativeElement ;
50- expect ( spinner ) . toBeTruthy ( ) ;
51-
52- httpMock . expectOne ( '/fake' ) . flush ( { } ) ;
53- tick ( ) ;
54- fixture . detectChanges ( ) ;
55-
56- spinner = fixture
57- . debugElement
58- . query ( By . css ( '#spinner' ) ) ;
59- expect ( spinner ) . toBeNull ( ) ;
60- }
61- ) ) ) ;
45+ it ( 'should work as expected when the host component has ChangeDetectionStrategy.OnPush' , fakeAsync ( ( ) => {
46+ http . get ( '/fake' ) . subscribe ( ) ;
47+ tick ( ) ;
48+ fixture . detectChanges ( ) ;
49+ let spinner = fixture
50+ . debugElement
51+ . query ( By . css ( '#spinner' ) )
52+ . nativeElement ;
53+ expect ( spinner ) . toBeTruthy ( ) ;
54+
55+ httpMock . expectOne ( '/fake' ) . flush ( { } ) ;
56+ tick ( ) ;
57+ fixture . detectChanges ( ) ;
58+
59+ spinner = fixture
60+ . debugElement
61+ . query ( By . css ( '#spinner' ) ) ;
62+ expect ( spinner ) . toBeNull ( ) ;
63+ } ) ) ;
6264} ) ;
0 commit comments