@@ -51,6 +51,11 @@ class MockBrowserXHR extends BrowserXhr {
51
51
}
52
52
53
53
setStatusCode ( status ) { this . status = status ; }
54
+
55
+ setResponse ( value ) { this . response = value ; }
56
+
57
+ setResponseText ( value ) { this . responseText = value ; }
58
+
54
59
addEventListener ( type : string , cb : Function ) { this . callbacks . set ( type , cb ) ; }
55
60
56
61
dispatchEvent ( type : string ) { this . callbacks . get ( type ) ( { } ) ; }
@@ -143,7 +148,7 @@ export function main() {
143
148
var connection = new XHRConnection ( sampleRequest , new MockBrowserXHR ( ) ,
144
149
new ResponseOptions ( { status : statusCode } ) ) ;
145
150
146
- ObservableWrapper . subscribe ( connection . response , res => {
151
+ ObservableWrapper . subscribe < Response > ( connection . response , res => {
147
152
expect ( res . status ) . toBe ( statusCode ) ;
148
153
async . done ( ) ;
149
154
} ) ;
@@ -158,14 +163,40 @@ export function main() {
158
163
var connection = new XHRConnection ( sampleRequest , new MockBrowserXHR ( ) ,
159
164
new ResponseOptions ( { status : statusCode } ) ) ;
160
165
161
- ObservableWrapper . subscribe ( connection . response , res => {
166
+ ObservableWrapper . subscribe < Response > ( connection . response , res => {
162
167
expect ( res . status ) . toBe ( normalizedCode ) ;
163
168
async . done ( ) ;
164
169
} ) ;
165
170
166
171
existingXHRs [ 0 ] . setStatusCode ( statusCode ) ;
167
172
existingXHRs [ 0 ] . dispatchEvent ( 'load' ) ;
168
173
} ) ) ;
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
+
169
200
} ) ;
170
201
} ) ;
171
202
}
0 commit comments