@@ -21,11 +21,6 @@ describe('Subject', () => {
21
21
subject . complete ( ) ;
22
22
} ) ;
23
23
24
- it ( 'should have the rxSubscriber Symbol' , ( ) => {
25
- const subject = new Subject ( ) ;
26
- expect ( subject [ Rx . Symbol . rxSubscriber ] ) . to . be . a ( 'function' ) ;
27
- } ) ;
28
-
29
24
it ( 'should pump values to multiple subscribers' , ( done : MochaDone ) => {
30
25
const subject = new Subject ( ) ;
31
26
const expected = [ 'foo' , 'bar' ] ;
@@ -276,82 +271,7 @@ describe('Subject', () => {
276
271
expect ( results3 ) . to . deep . equal ( [ ] ) ;
277
272
} ) ;
278
273
279
- it ( 'should allow ad-hoc subscription to be added to itself' , ( ) => {
280
- const subject = new Subject ( ) ;
281
- const results1 = [ ] ;
282
- const results2 = [ ] ;
283
-
284
- const auxSubject = new Subject ( ) ;
285
-
286
- const subscription1 = subject . subscribe (
287
- function ( x ) { results1 . push ( x ) ; } ,
288
- function ( e ) { results1 . push ( 'E' ) ; } ,
289
- ( ) => { results1 . push ( 'C' ) ; }
290
- ) ;
291
- const subscription2 = auxSubject . subscribe (
292
- function ( x ) { results2 . push ( x ) ; } ,
293
- function ( e ) { results2 . push ( 'E' ) ; } ,
294
- ( ) => { results2 . push ( 'C' ) ; }
295
- ) ;
296
-
297
- subject . add ( subscription2 ) ;
298
-
299
- subject . next ( 1 ) ;
300
- subject . next ( 2 ) ;
301
- subject . next ( 3 ) ;
302
- auxSubject . next ( 'a' ) ;
303
- auxSubject . next ( 'b' ) ;
304
-
305
- subscription1 . unsubscribe ( ) ;
306
- subject . unsubscribe ( ) ;
307
-
308
- auxSubject . next ( 'c' ) ;
309
- auxSubject . next ( 'd' ) ;
310
-
311
- expect ( results1 ) . to . deep . equal ( [ 1 , 2 , 3 ] ) ;
312
- expect ( subscription2 . isUnsubscribed ) . to . be . true ;
313
- expect ( results2 ) . to . deep . equal ( [ 'a' , 'b' ] ) ;
314
- } ) ;
315
-
316
- it ( 'should allow ad-hoc subscription to be removed from itself' , ( ) => {
317
- const subject = new Subject ( ) ;
318
- const results1 = [ ] ;
319
- const results2 = [ ] ;
320
-
321
- const auxSubject = new Subject ( ) ;
322
-
323
- const subscription1 = subject . subscribe (
324
- function ( x ) { results1 . push ( x ) ; } ,
325
- function ( e ) { results1 . push ( 'E' ) ; } ,
326
- ( ) => { results1 . push ( 'C' ) ; }
327
- ) ;
328
- const subscription2 = auxSubject . subscribe (
329
- function ( x ) { results2 . push ( x ) ; } ,
330
- function ( e ) { results2 . push ( 'E' ) ; } ,
331
- ( ) => { results2 . push ( 'C' ) ; }
332
- ) ;
333
-
334
- subject . add ( subscription2 ) ;
335
-
336
- subject . next ( 1 ) ;
337
- subject . next ( 2 ) ;
338
- subject . next ( 3 ) ;
339
- auxSubject . next ( 'a' ) ;
340
- auxSubject . next ( 'b' ) ;
341
-
342
- subject . remove ( subscription2 ) ;
343
- subscription1 . unsubscribe ( ) ;
344
- subject . unsubscribe ( ) ;
345
-
346
- auxSubject . next ( 'c' ) ;
347
- auxSubject . next ( 'd' ) ;
348
-
349
- expect ( results1 ) . to . deep . equal ( [ 1 , 2 , 3 ] ) ;
350
- expect ( subscription2 . isUnsubscribed ) . to . be . false ;
351
- expect ( results2 ) . to . deep . equal ( [ 'a' , 'b' , 'c' , 'd' ] ) ;
352
- } ) ;
353
-
354
- it ( 'should not allow values to be nexted after a return' , ( done : MochaDone ) => {
274
+ it ( 'should not allow values to be nexted after it is unsubscribed' , ( done : MochaDone ) => {
355
275
const subject = new Subject ( ) ;
356
276
const expected = [ 'foo' ] ;
357
277
@@ -360,7 +280,7 @@ describe('Subject', () => {
360
280
} ) ;
361
281
362
282
subject . next ( 'foo' ) ;
363
- subject . complete ( ) ;
283
+ subject . unsubscribe ( ) ;
364
284
expect ( ( ) => subject . next ( 'bar' ) ) . to . throw ( Rx . ObjectUnsubscribedError ) ;
365
285
done ( ) ;
366
286
} ) ;
@@ -528,38 +448,24 @@ describe('Subject', () => {
528
448
} ) . to . throw ( Rx . ObjectUnsubscribedError ) ;
529
449
} ) ;
530
450
531
- it ( 'should throw ObjectUnsubscribedError when emit after completed' , ( ) => {
451
+ it ( 'should not next after completed' , ( ) => {
532
452
const subject = new Rx . Subject ( ) ;
453
+ const results = [ ] ;
454
+ subject . subscribe ( x => results . push ( x ) , null , ( ) => results . push ( 'C' ) ) ;
455
+ subject . next ( 'a' ) ;
533
456
subject . complete ( ) ;
534
-
535
- expect ( ( ) => {
536
- subject . next ( 'a' ) ;
537
- } ) . to . throw ( Rx . ObjectUnsubscribedError ) ;
538
-
539
- expect ( ( ) => {
540
- subject . error ( 'a' ) ;
541
- } ) . to . throw ( Rx . ObjectUnsubscribedError ) ;
542
-
543
- expect ( ( ) => {
544
- subject . complete ( ) ;
545
- } ) . to . throw ( Rx . ObjectUnsubscribedError ) ;
457
+ subject . next ( 'b' ) ;
458
+ expect ( results ) . to . deep . equal ( [ 'a' , 'C' ] ) ;
546
459
} ) ;
547
460
548
- it ( 'should throw ObjectUnsubscribedError when emit after error' , ( ) => {
461
+ it ( 'should not next after error' , ( ) => {
549
462
const subject = new Rx . Subject ( ) ;
550
- subject . error ( 'e' ) ;
551
-
552
- expect ( ( ) => {
553
- subject . next ( 'a' ) ;
554
- } ) . to . throw ( Rx . ObjectUnsubscribedError ) ;
555
-
556
- expect ( ( ) => {
557
- subject . error ( 'a' ) ;
558
- } ) . to . throw ( Rx . ObjectUnsubscribedError ) ;
559
-
560
- expect ( ( ) => {
561
- subject . complete ( ) ;
562
- } ) . to . throw ( Rx . ObjectUnsubscribedError ) ;
463
+ const results = [ ] ;
464
+ subject . subscribe ( x => results . push ( x ) , ( err ) => results . push ( err ) ) ;
465
+ subject . next ( 'a' ) ;
466
+ subject . error ( new Error ( 'wut?' ) ) ;
467
+ subject . next ( 'b' ) ;
468
+ expect ( results ) . to . deep . equal ( [ 'a' , new Error ( 'wut?' ) ] ) ;
563
469
} ) ;
564
470
565
471
describe ( 'asObservable' , ( ) => {
@@ -600,43 +506,38 @@ describe('Subject', () => {
600
506
expectObservable ( observable ) . toBe ( expected ) ;
601
507
} ) ;
602
508
603
- it ( 'should work with inherited subject' , ( done : MochaDone ) => {
509
+ it ( 'should work with inherited subject' , ( ) => {
510
+ const results = [ ] ;
604
511
const subject = new Rx . AsyncSubject ( ) ;
605
512
606
513
subject . next ( 42 ) ;
607
514
subject . complete ( ) ;
608
515
609
516
const observable = subject . asObservable ( ) ;
610
517
611
- const expected = [ new Rx . Notification ( 'N' , 42 ) ,
612
- new Rx . Notification ( 'C' ) ] ;
518
+ observable . subscribe ( x => results . push ( x ) , null , ( ) => results . push ( 'done' ) ) ;
613
519
614
- observable . materialize ( ) . subscribe ( ( x : Rx . Notification < number > ) => {
615
- expect ( x ) . to . deep . equal ( expected . shift ( ) ) ;
616
- } , ( err : any ) => {
617
- done ( err ) ;
618
- } , ( ) => {
619
- expect ( expected ) . to . deep . equal ( [ ] ) ;
620
- done ( ) ;
621
- } ) ;
520
+ expect ( results ) . to . deep . equal ( [ 42 , 'done' ] ) ;
622
521
} ) ;
522
+ } ) ;
523
+ } ) ;
623
524
624
- it ( 'should not eager' , ( ) => {
625
- let subscribed = false ;
525
+ describe ( 'AnonymousSubject' , ( ) => {
526
+ it ( 'should not eager' , ( ) => {
527
+ let subscribed = false ;
626
528
627
- const subject = new Rx . Subject ( null , new Rx . Observable ( ( observer : Rx . Observer < any > ) => {
628
- subscribed = true ;
629
- const subscription = Rx . Observable . of ( 'x' ) . subscribe ( observer ) ;
630
- return ( ) => {
631
- subscription . unsubscribe ( ) ;
632
- } ;
633
- } ) ) ;
529
+ const subject = Rx . Subject . create ( null , new Rx . Observable ( ( observer : Rx . Observer < any > ) => {
530
+ subscribed = true ;
531
+ const subscription = Rx . Observable . of ( 'x' ) . subscribe ( observer ) ;
532
+ return ( ) => {
533
+ subscription . unsubscribe ( ) ;
534
+ } ;
535
+ } ) ) ;
634
536
635
- const observable = subject . asObservable ( ) ;
636
- expect ( subscribed ) . to . be . false ;
537
+ const observable = subject . asObservable ( ) ;
538
+ expect ( subscribed ) . to . be . false ;
637
539
638
- observable . subscribe ( ) ;
639
- expect ( subscribed ) . to . be . true ;
640
- } ) ;
540
+ observable . subscribe ( ) ;
541
+ expect ( subscribed ) . to . be . true ;
641
542
} ) ;
642
543
} ) ;
0 commit comments