@@ -39,6 +39,7 @@ class MockBrowserXHR extends BrowserXhr {
39
39
responseText : string ;
40
40
setRequestHeader : any ;
41
41
callbacks : Map < string , Function > ;
42
+ status : number ;
42
43
constructor ( ) {
43
44
super ( ) ;
44
45
var spy = new SpyObject ( ) ;
@@ -49,6 +50,7 @@ class MockBrowserXHR extends BrowserXhr {
49
50
this . callbacks = new Map ( ) ;
50
51
}
51
52
53
+ setStatusCode ( status ) { this . status = status ; }
52
54
addEventListener ( type : string , cb : Function ) { this . callbacks . set ( type , cb ) ; }
53
55
54
56
dispatchEvent ( type : string ) { this . callbacks . get ( type ) ( { } ) ; }
@@ -135,6 +137,35 @@ export function main() {
135
137
expect ( setRequestHeaderSpy ) . toHaveBeenCalledWith ( 'Content-Type' , [ 'text/xml' ] ) ;
136
138
expect ( setRequestHeaderSpy ) . toHaveBeenCalledWith ( 'Breaking-Bad' , [ '<3' ] ) ;
137
139
} ) ;
140
+
141
+ it ( 'should return the correct status code' , inject ( [ AsyncTestCompleter ] , async => {
142
+ var statusCode = 418 ;
143
+ var connection = new XHRConnection ( sampleRequest , new MockBrowserXHR ( ) ,
144
+ new ResponseOptions ( { status : statusCode } ) ) ;
145
+
146
+ ObservableWrapper . subscribe ( connection . response , res => {
147
+ expect ( res . status ) . toBe ( statusCode ) ;
148
+ async . done ( ) ;
149
+ } ) ;
150
+
151
+ existingXHRs [ 0 ] . setStatusCode ( statusCode ) ;
152
+ existingXHRs [ 0 ] . dispatchEvent ( 'load' ) ;
153
+ } ) ) ;
154
+
155
+ it ( 'should normalize IE\'s 1223 status code into 204' , inject ( [ AsyncTestCompleter ] , async => {
156
+ var statusCode = 1223 ;
157
+ var normalizedCode = 204 ;
158
+ var connection = new XHRConnection ( sampleRequest , new MockBrowserXHR ( ) ,
159
+ new ResponseOptions ( { status : statusCode } ) ) ;
160
+
161
+ ObservableWrapper . subscribe ( connection . response , res => {
162
+ expect ( res . status ) . toBe ( normalizedCode ) ;
163
+ async . done ( ) ;
164
+ } ) ;
165
+
166
+ existingXHRs [ 0 ] . setStatusCode ( statusCode ) ;
167
+ existingXHRs [ 0 ] . dispatchEvent ( 'load' ) ;
168
+ } ) ) ;
138
169
} ) ;
139
170
} ) ;
140
171
}
0 commit comments