@@ -51,6 +51,11 @@ class MockBrowserXHR extends BrowserXhr {
5151 }
5252
5353 setStatusCode ( status ) { this . status = status ; }
54+
55+ setResponse ( value ) { this . response = value ; }
56+
57+ setResponseText ( value ) { this . responseText = value ; }
58+
5459 addEventListener ( type : string , cb : Function ) { this . callbacks . set ( type , cb ) ; }
5560
5661 dispatchEvent ( type : string ) { this . callbacks . get ( type ) ( { } ) ; }
@@ -143,7 +148,7 @@ export function main() {
143148 var connection = new XHRConnection ( sampleRequest , new MockBrowserXHR ( ) ,
144149 new ResponseOptions ( { status : statusCode } ) ) ;
145150
146- ObservableWrapper . subscribe ( connection . response , res => {
151+ ObservableWrapper . subscribe < Response > ( connection . response , res => {
147152 expect ( res . status ) . toBe ( statusCode ) ;
148153 async . done ( ) ;
149154 } ) ;
@@ -158,14 +163,40 @@ export function main() {
158163 var connection = new XHRConnection ( sampleRequest , new MockBrowserXHR ( ) ,
159164 new ResponseOptions ( { status : statusCode } ) ) ;
160165
161- ObservableWrapper . subscribe ( connection . response , res => {
166+ ObservableWrapper . subscribe < Response > ( connection . response , res => {
162167 expect ( res . status ) . toBe ( normalizedCode ) ;
163168 async . done ( ) ;
164169 } ) ;
165170
166171 existingXHRs [ 0 ] . setStatusCode ( statusCode ) ;
167172 existingXHRs [ 0 ] . dispatchEvent ( 'load' ) ;
168173 } ) ) ;
174+
175+ it ( 'should normalize responseText and response' , inject ( [ AsyncTestCompleter ] , async => {
176+ var responseBody = 'Doge' ;
177+
178+ var connection1 =
179+ new XHRConnection ( sampleRequest , new MockBrowserXHR ( ) , new ResponseOptions ( ) ) ;
180+
181+ var connection2 =
182+ new XHRConnection ( sampleRequest , new MockBrowserXHR ( ) , new ResponseOptions ( ) ) ;
183+
184+ ObservableWrapper . subscribe < Response > ( connection1 . response , res => {
185+ expect ( res . text ( ) ) . toBe ( responseBody ) ;
186+
187+ ObservableWrapper . subscribe < Response > ( connection2 . response , ress => {
188+ expect ( ress . text ( ) ) . toBe ( responseBody ) ;
189+ async . done ( ) ;
190+ } ) ;
191+ existingXHRs [ 1 ] . dispatchEvent ( 'load' ) ;
192+ } ) ;
193+
194+ existingXHRs [ 0 ] . setResponseText ( responseBody ) ;
195+ existingXHRs [ 1 ] . setResponse ( responseBody ) ;
196+
197+ existingXHRs [ 0 ] . dispatchEvent ( 'load' ) ;
198+ } ) ) ;
199+
169200 } ) ;
170201 } ) ;
171202}
0 commit comments