@@ -12,8 +12,6 @@ import {HTTP_INTERCEPTORS, HttpClient, HttpClientModule, HttpEvent, HttpHandler,
12
12
import { HttpClientTestingModule , HttpTestingController } from '@angular/common/http/testing' ;
13
13
import { ApplicationRef , CompilerFactory , Component , HostListener , Inject , Injectable , Input , NgModule , NgZone , PLATFORM_ID , PlatformRef , ViewEncapsulation , destroyPlatform , getPlatform } from '@angular/core' ;
14
14
import { async , inject } from '@angular/core/testing' ;
15
- import { Http , HttpModule , Response , ResponseOptions , XHRBackend } from '@angular/http' ;
16
- import { MockBackend , MockConnection } from '@angular/http/testing' ;
17
15
import { BrowserModule , Title , TransferState , makeStateKey } from '@angular/platform-browser' ;
18
16
import { getDOM } from '@angular/platform-browser/src/dom/dom_adapter' ;
19
17
import { BEFORE_APP_SERIALIZED , INITIAL_CONFIG , PlatformState , ServerModule , ServerTransferStateModule , platformDynamicServer , renderModule , renderModuleFactory } from '@angular/platform-server' ;
@@ -29,10 +27,6 @@ class MyServerApp {
29
27
bootstrap : [ MyServerApp ] ,
30
28
declarations : [ MyServerApp ] ,
31
29
imports : [ ServerModule ] ,
32
- providers : [
33
- MockBackend ,
34
- { provide : XHRBackend , useExisting : MockBackend } ,
35
- ]
36
30
} )
37
31
class ExampleModule {
38
32
}
@@ -232,30 +226,6 @@ class MyStylesApp {
232
226
class ExampleStylesModule {
233
227
}
234
228
235
- @NgModule ( {
236
- bootstrap : [ MyServerApp ] ,
237
- declarations : [ MyServerApp ] ,
238
- imports : [ HttpModule , ServerModule ] ,
239
- providers : [
240
- MockBackend ,
241
- { provide : XHRBackend , useExisting : MockBackend } ,
242
- ]
243
- } )
244
- export class HttpBeforeExampleModule {
245
- }
246
-
247
- @NgModule ( {
248
- bootstrap : [ MyServerApp ] ,
249
- declarations : [ MyServerApp ] ,
250
- imports : [ ServerModule , HttpModule ] ,
251
- providers : [
252
- MockBackend ,
253
- { provide : XHRBackend , useExisting : MockBackend } ,
254
- ]
255
- } )
256
- export class HttpAfterExampleModule {
257
- }
258
-
259
229
@NgModule ( {
260
230
bootstrap : [ MyServerApp ] ,
261
231
declarations : [ MyServerApp ] ,
@@ -774,108 +744,6 @@ class HiddenModule {
774
744
} ) ) ;
775
745
} ) ;
776
746
777
- describe ( 'http' , ( ) => {
778
- it ( 'can inject Http' , async ( ( ) => {
779
- const platform = platformDynamicServer (
780
- [ { provide : INITIAL_CONFIG , useValue : { document : '<app></app>' } } ] ) ;
781
- platform . bootstrapModule ( ExampleModule ) . then ( ref => {
782
- expect ( ref . injector . get ( Http ) instanceof Http ) . toBeTruthy ( ) ;
783
- } ) ;
784
- } ) ) ;
785
-
786
- it ( 'can make Http requests' , async ( ( ) => {
787
- const platform = platformDynamicServer (
788
- [ { provide : INITIAL_CONFIG , useValue : { document : '<app></app>' } } ] ) ;
789
- platform . bootstrapModule ( ExampleModule ) . then ( ref => {
790
- const mock = ref . injector . get ( MockBackend ) ;
791
- const http = ref . injector . get ( Http ) ;
792
- ref . injector . get < NgZone > ( NgZone ) . run ( ( ) => {
793
- NgZone . assertInAngularZone ( ) ;
794
- mock . connections . subscribe ( ( mc : MockConnection ) => {
795
- NgZone . assertInAngularZone ( ) ;
796
- expect ( mc . request . url ) . toBe ( 'http://localhost/testing' ) ;
797
- mc . mockRespond ( new Response ( new ResponseOptions ( { body : 'success!' , status : 200 } ) ) ) ;
798
- } ) ;
799
- http . get ( 'http://localhost/testing' ) . subscribe ( resp => {
800
- NgZone . assertInAngularZone ( ) ;
801
- expect ( resp . text ( ) ) . toBe ( 'success!' ) ;
802
- } ) ;
803
- } ) ;
804
- } ) ;
805
- } ) ) ;
806
-
807
- it ( 'requests are macrotasks' , async ( ( ) => {
808
- const platform = platformDynamicServer (
809
- [ { provide : INITIAL_CONFIG , useValue : { document : '<app></app>' } } ] ) ;
810
- platform . bootstrapModule ( ExampleModule ) . then ( ref => {
811
- const mock = ref . injector . get ( MockBackend ) ;
812
- const http = ref . injector . get ( Http ) ;
813
- expect ( ref . injector . get < NgZone > ( NgZone ) . hasPendingMacrotasks ) . toBeFalsy ( ) ;
814
- ref . injector . get < NgZone > ( NgZone ) . run ( ( ) => {
815
- NgZone . assertInAngularZone ( ) ;
816
- mock . connections . subscribe ( ( mc : MockConnection ) => {
817
- expect ( ref . injector . get < NgZone > ( NgZone ) . hasPendingMacrotasks ) . toBeTruthy ( ) ;
818
- mc . mockRespond ( new Response ( new ResponseOptions ( { body : 'success!' , status : 200 } ) ) ) ;
819
- } ) ;
820
- http . get ( 'http://localhost/testing' ) . subscribe ( resp => {
821
- expect ( resp . text ( ) ) . toBe ( 'success!' ) ;
822
- } ) ;
823
- } ) ;
824
- } ) ;
825
- } ) ) ;
826
-
827
- it ( 'works when HttpModule is included before ServerModule' , async ( ( ) => {
828
- const platform = platformDynamicServer (
829
- [ { provide : INITIAL_CONFIG , useValue : { document : '<app></app>' } } ] ) ;
830
- platform . bootstrapModule ( HttpBeforeExampleModule ) . then ( ref => {
831
- const mock = ref . injector . get ( MockBackend ) ;
832
- const http = ref . injector . get ( Http ) ;
833
- expect ( ref . injector . get < NgZone > ( NgZone ) . hasPendingMacrotasks ) . toBeFalsy ( ) ;
834
- ref . injector . get < NgZone > ( NgZone ) . run ( ( ) => {
835
- NgZone . assertInAngularZone ( ) ;
836
- mock . connections . subscribe ( ( mc : MockConnection ) => {
837
- expect ( ref . injector . get < NgZone > ( NgZone ) . hasPendingMacrotasks ) . toBeTruthy ( ) ;
838
- mc . mockRespond ( new Response ( new ResponseOptions ( { body : 'success!' , status : 200 } ) ) ) ;
839
- } ) ;
840
- http . get ( 'http://localhost/testing' ) . subscribe ( resp => {
841
- expect ( resp . text ( ) ) . toBe ( 'success!' ) ;
842
- } ) ;
843
- } ) ;
844
- } ) ;
845
- } ) ) ;
846
-
847
- it ( 'works when HttpModule is included after ServerModule' , async ( ( ) => {
848
- const platform = platformDynamicServer (
849
- [ { provide : INITIAL_CONFIG , useValue : { document : '<app></app>' } } ] ) ;
850
- platform . bootstrapModule ( HttpAfterExampleModule ) . then ( ref => {
851
- const mock = ref . injector . get ( MockBackend ) ;
852
- const http = ref . injector . get ( Http ) ;
853
- expect ( ref . injector . get < NgZone > ( NgZone ) . hasPendingMacrotasks ) . toBeFalsy ( ) ;
854
- ref . injector . get < NgZone > ( NgZone ) . run ( ( ) => {
855
- NgZone . assertInAngularZone ( ) ;
856
- mock . connections . subscribe ( ( mc : MockConnection ) => {
857
- expect ( ref . injector . get < NgZone > ( NgZone ) . hasPendingMacrotasks ) . toBeTruthy ( ) ;
858
- mc . mockRespond ( new Response ( new ResponseOptions ( { body : 'success!' , status : 200 } ) ) ) ;
859
- } ) ;
860
- http . get ( 'http://localhost/testing' ) . subscribe ( resp => {
861
- expect ( resp . text ( ) ) . toBe ( 'success!' ) ;
862
- } ) ;
863
- } ) ;
864
- } ) ;
865
- } ) ) ;
866
-
867
- it ( 'throws when given a relative URL' , async ( ( ) => {
868
- const platform = platformDynamicServer (
869
- [ { provide : INITIAL_CONFIG , useValue : { document : '<app></app>' } } ] ) ;
870
- platform . bootstrapModule ( ExampleModule ) . then ( ref => {
871
- const http = ref . injector . get ( Http ) ;
872
- expect ( ( ) => http . get ( '/testing' ) )
873
- . toThrowError (
874
- 'URLs requested via Http on the server must be absolute. URL: /testing' ) ;
875
- } ) ;
876
- } ) ) ;
877
- } ) ;
878
-
879
747
describe ( 'HttpClient' , ( ) => {
880
748
it ( 'can inject HttpClient' , async ( ( ) => {
881
749
const platform = platformDynamicServer (
0 commit comments