@@ -141,68 +141,6 @@ describe('Observable.ajax', () => {
141
141
} ) ;
142
142
} ) ;
143
143
144
- it ( 'should have an optional resultSelector' , ( ) => {
145
- const expected = 'avast ye swabs!' ;
146
- let result ;
147
- let complete = false ;
148
-
149
- const obj = {
150
- url : '/flibbertyJibbet' ,
151
- responseType : 'text' ,
152
- resultSelector : ( res : any ) => res . response
153
- } ;
154
-
155
- ( < any > Rx . Observable . ajax ) ( obj )
156
- . subscribe ( ( x : any ) => {
157
- result = x ;
158
- } , null , ( ) => {
159
- complete = true ;
160
- } ) ;
161
-
162
- expect ( MockXMLHttpRequest . mostRecent . url ) . to . equal ( '/flibbertyJibbet' ) ;
163
-
164
- MockXMLHttpRequest . mostRecent . respondWith ( {
165
- 'status' : 200 ,
166
- 'contentType' : 'application/json' ,
167
- 'responseText' : expected
168
- } ) ;
169
-
170
- expect ( result ) . to . equal ( expected ) ;
171
- expect ( complete ) . to . be . true ;
172
- } ) ;
173
-
174
- it ( 'should have error when resultSelector errors' , ( ) => {
175
- const expected = 'avast ye swabs!' ;
176
- let error ;
177
- const obj = {
178
- url : '/flibbertyJibbet' ,
179
- responseType : 'text' ,
180
- resultSelector : ( res : any ) => {
181
- throw new Error ( 'ha! ha! fooled you!' ) ;
182
- } ,
183
- method : ''
184
- } ;
185
-
186
- Rx . Observable . ajax ( obj )
187
- . subscribe ( ( x : any ) => {
188
- throw 'should not next' ;
189
- } , ( err : any ) => {
190
- error = err ;
191
- } , ( ) => {
192
- throw 'should not complete' ;
193
- } ) ;
194
-
195
- expect ( MockXMLHttpRequest . mostRecent . url ) . to . equal ( '/flibbertyJibbet' ) ;
196
-
197
- MockXMLHttpRequest . mostRecent . respondWith ( {
198
- 'status' : 200 ,
199
- 'contentType' : 'application/json' ,
200
- 'responseText' : expected
201
- } ) ;
202
-
203
- expect ( error ) . to . be . an ( 'error' , 'ha! ha! fooled you!' ) ;
204
- } ) ;
205
-
206
144
it ( 'should error if createXHR throws' , ( ) => {
207
145
let error ;
208
146
const obj = {
@@ -213,7 +151,7 @@ describe('Observable.ajax', () => {
213
151
}
214
152
} ;
215
153
216
- ( < any > Rx . Observable . ajax ) ( obj )
154
+ Rx . Observable . ajax ( < any > obj )
217
155
. subscribe ( ( x : any ) => {
218
156
throw 'should not next' ;
219
157
} , ( err : any ) => {
@@ -299,13 +237,13 @@ describe('Observable.ajax', () => {
299
237
method : ''
300
238
} ;
301
239
302
- Rx . Observable . ajax ( obj ) . subscribe ( ( x : any ) => {
303
- throw 'should not next' ;
304
- } , ( err : any ) => {
305
- error = err ;
306
- } , ( ) => {
307
- throw 'should not complete' ;
308
- } ) ;
240
+ Rx . Observable . ajax ( obj ) . subscribe ( x => {
241
+ throw 'should not next' ;
242
+ } , ( err : any ) => {
243
+ error = err ;
244
+ } , ( ) => {
245
+ throw 'should not complete' ;
246
+ } ) ;
309
247
310
248
expect ( MockXMLHttpRequest . mostRecent . url ) . to . equal ( '/flibbertyJibbet' ) ;
311
249
@@ -324,13 +262,13 @@ describe('Observable.ajax', () => {
324
262
const expected = JSON . stringify ( { foo : 'bar' } ) ;
325
263
326
264
Rx . Observable . ajax ( '/flibbertyJibbet' )
327
- . subscribe ( ( x : any ) => {
328
- expect ( x . status ) . to . equal ( 200 ) ;
329
- expect ( x . xhr . method ) . to . equal ( 'GET' ) ;
330
- expect ( x . xhr . responseText ) . to . equal ( expected ) ;
331
- } , ( ) => {
332
- throw 'should not have been called' ;
333
- } ) ;
265
+ . subscribe ( ( x : any ) => {
266
+ expect ( x . status ) . to . equal ( 200 ) ;
267
+ expect ( x . xhr . method ) . to . equal ( 'GET' ) ;
268
+ expect ( x . xhr . responseText ) . to . equal ( expected ) ;
269
+ } , ( ) => {
270
+ throw 'should not have been called' ;
271
+ } ) ;
334
272
335
273
expect ( MockXMLHttpRequest . mostRecent . url ) . to . equal ( '/flibbertyJibbet' ) ;
336
274
MockXMLHttpRequest . mostRecent . respondWith ( {
@@ -344,15 +282,15 @@ describe('Observable.ajax', () => {
344
282
const expected = JSON . stringify ( { foo : 'bar' } ) ;
345
283
346
284
Rx . Observable . ajax ( '/flibbertyJibbet' )
347
- . subscribe ( ( ) => {
348
- throw 'should not have been called' ;
349
- } , ( x : any ) => {
350
- expect ( x . status ) . to . equal ( 500 ) ;
351
- expect ( x . xhr . method ) . to . equal ( 'GET' ) ;
352
- expect ( x . xhr . responseText ) . to . equal ( expected ) ;
353
- } , ( ) => {
354
- throw 'should not have been called' ;
355
- } ) ;
285
+ . subscribe ( ( ) => {
286
+ throw 'should not have been called' ;
287
+ } , ( x : any ) => {
288
+ expect ( x . status ) . to . equal ( 500 ) ;
289
+ expect ( x . xhr . method ) . to . equal ( 'GET' ) ;
290
+ expect ( x . xhr . responseText ) . to . equal ( expected ) ;
291
+ } , ( ) => {
292
+ throw 'should not have been called' ;
293
+ } ) ;
356
294
357
295
expect ( MockXMLHttpRequest . mostRecent . url ) . to . equal ( '/flibbertyJibbet' ) ;
358
296
MockXMLHttpRequest . mostRecent . respondWith ( {
@@ -367,7 +305,7 @@ describe('Observable.ajax', () => {
367
305
368
306
beforeEach ( ( ) => {
369
307
rFormData = root . FormData ;
370
- root . FormData = root . FormData || class { } ;
308
+ root . FormData = root . FormData || class { } ;
371
309
} ) ;
372
310
373
311
afterEach ( ( ) => {
@@ -468,8 +406,8 @@ describe('Observable.ajax', () => {
468
406
469
407
Rx . Observable
470
408
. ajax . get ( '/flibbertyJibbet' )
471
- . subscribe ( ( x : any ) => {
472
- result = x ;
409
+ . subscribe ( x => {
410
+ result = x . response ;
473
411
} , null , ( ) => {
474
412
complete = true ;
475
413
} ) ;
@@ -488,70 +426,39 @@ describe('Observable.ajax', () => {
488
426
expect ( complete ) . to . be . true ;
489
427
} ) ;
490
428
491
- it ( 'should succeed on 200 with a resultSelector' , ( ) => {
492
- const expected = { larf : 'hahahahaha' } ;
493
- let result ;
494
- let innerResult ;
495
- let complete = false ;
496
-
497
- Rx . Observable
498
- . ajax . get ( '/flibbertyJibbet' , ( x : any ) => {
499
- innerResult = x ;
500
- return x . response . larf . toUpperCase ( ) ;
501
- } )
502
- . subscribe ( ( x : any ) => {
503
- result = x ;
504
- } , null , ( ) => {
505
- complete = true ;
429
+ describe ( 'ajax.post' , ( ) => {
430
+ it ( 'should succeed on 200' , ( ) => {
431
+ const expected = { foo : 'bar' , hi : 'there you' } ;
432
+ let result : Rx . AjaxResponse ;
433
+ let complete = false ;
434
+
435
+ Rx . Observable
436
+ . ajax . post ( '/flibbertyJibbet' , expected )
437
+ . subscribe ( x => {
438
+ result = x ;
439
+ } , null , ( ) => {
440
+ complete = true ;
441
+ } ) ;
442
+
443
+ const request = MockXMLHttpRequest . mostRecent ;
444
+
445
+ expect ( request . method ) . to . equal ( 'POST' ) ;
446
+ expect ( request . url ) . to . equal ( '/flibbertyJibbet' ) ;
447
+ expect ( request . requestHeaders ) . to . deep . equal ( {
448
+ 'X-Requested-With' : 'XMLHttpRequest' ,
449
+ 'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'
506
450
} ) ;
507
451
508
- expect ( MockXMLHttpRequest . mostRecent . url ) . to . equal ( '/flibbertyJibbet' ) ;
509
-
510
- MockXMLHttpRequest . mostRecent . respondWith ( {
511
- 'status' : 200 ,
512
- 'contentType' : 'application/json' ,
513
- 'responseText' : JSON . stringify ( expected )
514
- } ) ;
515
-
516
- expect ( innerResult . xhr ) . exist ;
517
- expect ( innerResult . response ) . to . deep . equal ( { larf : 'hahahahaha' } ) ;
518
- expect ( result ) . to . equal ( 'HAHAHAHAHA' ) ;
519
- expect ( complete ) . to . be . true ;
520
- } ) ;
521
- } ) ;
522
-
523
- describe ( 'ajax.post' , ( ) => {
524
- it ( 'should succeed on 200' , ( ) => {
525
- const expected = { foo : 'bar' , hi : 'there you' } ;
526
- let result ;
527
- let complete = false ;
528
-
529
- Rx . Observable
530
- . ajax . post ( '/flibbertyJibbet' , expected )
531
- . subscribe ( ( x : any ) => {
532
- result = x ;
533
- } , null , ( ) => {
534
- complete = true ;
452
+ request . respondWith ( {
453
+ 'status' : 200 ,
454
+ 'contentType' : 'application/json' ,
455
+ 'responseText' : JSON . stringify ( expected )
535
456
} ) ;
536
457
537
- const request = MockXMLHttpRequest . mostRecent ;
538
-
539
- expect ( request . method ) . to . equal ( 'POST' ) ;
540
- expect ( request . url ) . to . equal ( '/flibbertyJibbet' ) ;
541
- expect ( request . requestHeaders ) . to . deep . equal ( {
542
- 'X-Requested-With' : 'XMLHttpRequest' ,
543
- 'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'
544
- } ) ;
545
-
546
- request . respondWith ( {
547
- 'status' : 200 ,
548
- 'contentType' : 'application/json' ,
549
- 'responseText' : JSON . stringify ( expected )
458
+ expect ( request . data ) . to . equal ( 'foo=bar&hi=there%20you' ) ;
459
+ expect ( result . response ) . to . deep . equal ( expected ) ;
460
+ expect ( complete ) . to . be . true ;
550
461
} ) ;
551
-
552
- expect ( request . data ) . to . equal ( 'foo=bar&hi=there%20you' ) ;
553
- expect ( result . response ) . to . deep . equal ( expected ) ;
554
- expect ( complete ) . to . be . true ;
555
462
} ) ;
556
463
} ) ;
557
- } ) ;
464
+ } ) ;
0 commit comments