@@ -99,6 +99,7 @@ export function main() {
9999 expect ( res . type ) . toBe ( ResponseTypes . Error ) ;
100100 async . done ( ) ;
101101 } ) ;
102+ existingXHRs [ 0 ] . setStatusCode ( 200 ) ;
102103 existingXHRs [ 0 ] . dispatchEvent ( 'load' ) ;
103104 } ) ) ;
104105
@@ -107,7 +108,7 @@ export function main() {
107108 new ResponseOptions ( { type : ResponseTypes . Error } ) ) ;
108109 connection . response . subscribe ( res => { expect ( res . type ) . toBe ( ResponseTypes . Error ) ; } ,
109110 null , ( ) => { async . done ( ) ; } ) ;
110-
111+ existingXHRs [ 0 ] . setStatusCode ( 200 ) ;
111112 existingXHRs [ 0 ] . dispatchEvent ( 'load' ) ;
112113 } ) ) ;
113114
@@ -164,15 +165,57 @@ export function main() {
164165 var connection = new XHRConnection ( sampleRequest , new MockBrowserXHR ( ) ,
165166 new ResponseOptions ( { status : statusCode } ) ) ;
166167
167- connection . response . subscribe ( res => {
168- expect ( res . status ) . toBe ( statusCode ) ;
169- async . done ( ) ;
170- } ) ;
168+ connection . response . subscribe (
169+ res => {
170+
171+ } ,
172+ errRes => {
173+ expect ( errRes . status ) . toBe ( statusCode ) ;
174+ async . done ( ) ;
175+ } ) ;
176+
177+ existingXHRs [ 0 ] . setStatusCode ( statusCode ) ;
178+ existingXHRs [ 0 ] . dispatchEvent ( 'load' ) ;
179+ } ) ) ;
180+
181+ it ( 'should call next and complete on 200 codes' , inject ( [ AsyncTestCompleter ] , async => {
182+ var nextCalled = false ;
183+ var errorCalled = false ;
184+ var statusCode = 200 ;
185+ var connection = new XHRConnection ( sampleRequest , new MockBrowserXHR ( ) ,
186+ new ResponseOptions ( { status : statusCode } ) ) ;
187+
188+ connection . response . subscribe (
189+ res => {
190+ nextCalled = true ;
191+ expect ( res . status ) . toBe ( statusCode ) ;
192+ } ,
193+ errRes => { errorCalled = true ; } , ( ) => {
194+ expect ( nextCalled ) . toBe ( true ) ;
195+ expect ( errorCalled ) . toBe ( false ) ;
196+ async . done ( ) ;
197+ } ) ;
171198
172199 existingXHRs [ 0 ] . setStatusCode ( statusCode ) ;
173200 existingXHRs [ 0 ] . dispatchEvent ( 'load' ) ;
174201 } ) ) ;
175202
203+ it ( 'should call error and not complete on 300+ codes' , inject ( [ AsyncTestCompleter ] , async => {
204+ var nextCalled = false ;
205+ var errorCalled = false ;
206+ var statusCode = 301 ;
207+ var connection = new XHRConnection ( sampleRequest , new MockBrowserXHR ( ) ,
208+ new ResponseOptions ( { status : statusCode } ) ) ;
209+
210+ connection . response . subscribe ( res => { nextCalled = true ; } , errRes => {
211+ expect ( errRes . status ) . toBe ( statusCode ) ;
212+ expect ( nextCalled ) . toBe ( false ) ;
213+ async . done ( ) ;
214+ } , ( ) => { throw 'should not be called' ; } ) ;
215+
216+ existingXHRs [ 0 ] . setStatusCode ( statusCode ) ;
217+ existingXHRs [ 0 ] . dispatchEvent ( 'load' ) ;
218+ } ) ) ;
176219 it ( 'should normalize IE\'s 1223 status code into 204' , inject ( [ AsyncTestCompleter ] , async => {
177220 var statusCode = 1223 ;
178221 var normalizedCode = 204 ;
@@ -204,10 +247,11 @@ export function main() {
204247 expect ( ress . text ( ) ) . toBe ( responseBody ) ;
205248 async . done ( ) ;
206249 } ) ;
250+ existingXHRs [ 1 ] . setStatusCode ( 200 ) ;
207251 existingXHRs [ 1 ] . setResponse ( responseBody ) ;
208252 existingXHRs [ 1 ] . dispatchEvent ( 'load' ) ;
209253 } ) ;
210-
254+ existingXHRs [ 0 ] . setStatusCode ( 200 ) ;
211255 existingXHRs [ 0 ] . setResponseText ( responseBody ) ;
212256 existingXHRs [ 0 ] . dispatchEvent ( 'load' ) ;
213257 } ) ) ;
0 commit comments