@@ -2,7 +2,7 @@ import { expect } from 'chai';
2
2
import * as sinon from 'sinon' ;
3
3
import { TeardownLogic } from '../src/internal/types' ;
4
4
import { Observable , config , Subscription , Subscriber , Operator , NEVER , Subject , of , throwError , EMPTY } from 'rxjs' ;
5
- import { map , filter , count , tap , combineLatestWith , concatWith , mergeWith , raceWith , zipWith , catchError , share } from 'rxjs/operators' ;
5
+ import { map , filter , count , tap , combineLatestWith , concatWith , mergeWith , raceWith , zipWith , catchError , share } from 'rxjs/operators' ;
6
6
import { TestScheduler } from 'rxjs/testing' ;
7
7
import { observableMatcher } from './helpers/observableMatcher' ;
8
8
import { result } from 'lodash' ;
@@ -30,11 +30,12 @@ describe('Observable', () => {
30
30
observer . complete ( ) ;
31
31
} ) ;
32
32
33
- source . subscribe (
34
- { next : function ( x ) {
33
+ source . subscribe ( {
34
+ next : function ( x ) {
35
35
expect ( x ) . to . equal ( 1 ) ;
36
- } , complete : done }
37
- ) ;
36
+ } ,
37
+ complete : done ,
38
+ } ) ;
38
39
} ) ;
39
40
40
41
it ( 'should send errors thrown in the constructor down the error path' , ( done ) => {
@@ -70,7 +71,7 @@ describe('Observable', () => {
70
71
} ) ;
71
72
72
73
it ( 'should reject promise when in error' , ( done ) => {
73
- throwError ( ( ) => ( 'bad' ) )
74
+ throwError ( ( ) => 'bad' )
74
75
. forEach ( ( ) => {
75
76
done ( new Error ( 'should not be called' ) ) ;
76
77
} )
@@ -178,13 +179,17 @@ describe('Observable', () => {
178
179
const results : any [ ] = [ ] ;
179
180
const next = function ( value : string ) {
180
181
results . push ( value ) ;
181
- }
182
- next . bind = ( ) => { /* lol */ } ;
182
+ } ;
183
+ next . bind = ( ) => {
184
+ /* lol */
185
+ } ;
183
186
184
187
const complete = function ( ) {
185
188
results . push ( 'done' ) ;
186
- }
187
- complete . bind = ( ) => { /* lol */ } ;
189
+ } ;
190
+ complete . bind = ( ) => {
191
+ /* lol */
192
+ } ;
188
193
189
194
source . subscribe ( { next, complete } ) ;
190
195
expect ( results ) . to . deep . equal ( [ 'Hi' , 'done' ] ) ;
@@ -195,7 +200,7 @@ describe('Observable', () => {
195
200
const results : any [ ] = [ ] ;
196
201
const error = function ( value : string ) {
197
202
results . push ( value ) ;
198
- }
203
+ } ;
199
204
200
205
source . subscribe ( { error } ) ;
201
206
expect ( results ) . to . deep . equal ( [ 'an error' ] ) ;
@@ -218,15 +223,16 @@ describe('Observable', () => {
218
223
let mutatedByNext = false ;
219
224
let mutatedByComplete = false ;
220
225
221
- source . subscribe (
222
- { next : ( x ) => {
226
+ source . subscribe ( {
227
+ next : ( x ) => {
223
228
nexted = x ;
224
229
mutatedByNext = true ;
225
- } , complete : ( ) => {
230
+ } ,
231
+ complete : ( ) => {
226
232
completed = true ;
227
233
mutatedByComplete = true ;
228
- } }
229
- ) ;
234
+ } ,
235
+ } ) ;
230
236
231
237
expect ( mutatedByNext ) . to . be . true ;
232
238
expect ( mutatedByComplete ) . to . be . true ;
@@ -387,15 +393,16 @@ describe('Observable', () => {
387
393
} ;
388
394
} )
389
395
. pipe ( tap ( ( ) => ( times += 1 ) ) )
390
- . subscribe (
391
- { next : function ( ) {
396
+ . subscribe ( {
397
+ next : function ( ) {
392
398
if ( times === 2 ) {
393
399
subscription . unsubscribe ( ) ;
394
400
}
395
- } , error : function ( ) {
401
+ } ,
402
+ error : function ( ) {
396
403
errorCalled = true ;
397
- } }
398
- ) ;
404
+ } ,
405
+ } ) ;
399
406
} ) ;
400
407
401
408
it ( 'should ignore complete messages after unsubscription' , ( done ) => {
@@ -419,15 +426,16 @@ describe('Observable', () => {
419
426
} ;
420
427
} )
421
428
. pipe ( tap ( ( ) => ( times += 1 ) ) )
422
- . subscribe (
423
- { next : function ( ) {
429
+ . subscribe ( {
430
+ next : function ( ) {
424
431
if ( times === 2 ) {
425
432
subscription . unsubscribe ( ) ;
426
433
}
427
- } , complete : function ( ) {
434
+ } ,
435
+ complete : function ( ) {
428
436
completeCalled = true ;
429
- } }
430
- ) ;
437
+ } ,
438
+ } ) ;
431
439
} ) ;
432
440
433
441
describe ( 'when called with an anonymous observer' , ( ) => {
@@ -463,7 +471,7 @@ describe('Observable', () => {
463
471
} ,
464
472
} ;
465
473
466
- throwError ( ( ) => ( 'bad' ) ) . subscribe ( o ) ;
474
+ throwError ( ( ) => 'bad' ) . subscribe ( o ) ;
467
475
}
468
476
) ;
469
477
@@ -592,13 +600,14 @@ describe('Observable', () => {
592
600
} ) ;
593
601
594
602
badObservable . subscribe ( {
595
- error : ( ) => { /* do nothing */ }
603
+ error : ( ) => {
604
+ /* do nothing */
605
+ } ,
596
606
} ) ;
597
607
598
608
expect ( called ) . to . be . true ;
599
609
} ) ;
600
610
601
-
602
611
it ( 'should handle empty string sync errors' , ( ) => {
603
612
const badObservable = new Observable ( ( ) => {
604
613
throw '' ;
@@ -609,7 +618,7 @@ describe('Observable', () => {
609
618
error : ( err ) => {
610
619
caught = true ;
611
620
expect ( err ) . to . equal ( '' ) ;
612
- }
621
+ } ,
613
622
} ) ;
614
623
expect ( caught ) . to . be . true ;
615
624
} ) ;
@@ -627,11 +636,12 @@ describe('Observable', () => {
627
636
map ( ( x ) => x + x ) ,
628
637
map ( ( x ) => x + '!!!' )
629
638
)
630
- . subscribe (
631
- { next : ( x ) => {
639
+ . subscribe ( {
640
+ next : ( x ) => {
632
641
expect ( x ) . to . equal ( 'testtest!!!' ) ;
633
- } , complete : done }
634
- ) ;
642
+ } ,
643
+ complete : done ,
644
+ } ) ;
635
645
} ) ;
636
646
637
647
it ( 'should return the same observable if there are no arguments' , ( ) => {
@@ -643,11 +653,11 @@ describe('Observable', () => {
643
653
it ( 'should allow any kind of piped function' , ( ) => {
644
654
const source = of ( 'test' ) ;
645
655
const result = source . pipe (
646
- source => source instanceof Observable ,
647
- isObservable => isObservable ? 'Well hello, there.' : 'Huh?'
656
+ ( source ) => source instanceof Observable ,
657
+ ( isObservable ) => ( isObservable ? 'Well hello, there.' : 'Huh?' )
648
658
) ;
649
659
expect ( result ) . to . equal ( 'Well hello, there.' ) ;
650
- } )
660
+ } ) ;
651
661
} ) ;
652
662
653
663
it ( 'should not swallow internal errors' , ( done ) => {
@@ -658,29 +668,29 @@ describe('Observable', () => {
658
668
done ( ) ;
659
669
} ;
660
670
661
- new Observable ( subscriber => {
671
+ new Observable ( ( subscriber ) => {
662
672
subscriber . error ( 'test' ) ;
663
673
throw 'bad' ;
664
674
} ) . subscribe ( {
665
- error : err => {
675
+ error : ( err ) => {
666
676
expect ( err ) . to . equal ( 'test' ) ;
667
- }
677
+ } ,
668
678
} ) ;
669
679
} ) ;
670
680
671
681
// Discussion here: https://github.com/ReactiveX/rxjs/issues/5370
672
682
it . skip ( 'should handle sync errors within a test scheduler' , ( ) => {
673
683
const observable = of ( 4 ) . pipe (
674
- map ( n => {
675
- if ( n === 4 ) {
676
- throw 'four!' ;
684
+ map ( ( n ) => {
685
+ if ( n === 4 ) {
686
+ throw 'four!' ;
677
687
}
678
688
return n ;
679
689
} ) ,
680
- catchError ( ( err , source ) => source ) ,
690
+ catchError ( ( err , source ) => source )
681
691
) ;
682
692
683
- rxTestScheduler . run ( helpers => {
693
+ rxTestScheduler . run ( ( helpers ) => {
684
694
const { expectObservable } = helpers ;
685
695
expectObservable ( observable ) . toBe ( '-' ) ;
686
696
} ) ;
@@ -694,14 +704,13 @@ describe('Observable', () => {
694
704
695
705
let thrownError : any = undefined ;
696
706
source . subscribe ( {
697
- error : err => thrownError = err
707
+ error : ( err ) => ( thrownError = err ) ,
698
708
} ) ;
699
709
700
710
expect ( thrownError ) . to . be . an . instanceOf ( RangeError ) ;
701
711
expect ( thrownError . message ) . to . equal ( 'Maximum call stack size exceeded' ) ;
702
712
} ) ;
703
713
704
-
705
714
describe ( 'As an async iterable' , ( ) => {
706
715
it ( 'should be able to be used with for-await-of' , async ( ) => {
707
716
const source = new Observable < number > ( ( subscriber ) => {
@@ -727,13 +736,13 @@ describe('Observable', () => {
727
736
728
737
subscriber . next ( 1 ) ;
729
738
subscriber . next ( 2 ) ;
730
-
739
+
731
740
// NOTE that we are NOT calling `subscriber.complete()` here.
732
741
// therefore the teardown below would never be called naturally
733
742
// by the observable unless it was unsubscribed.
734
743
return ( ) => {
735
744
activeSubscriptions -- ;
736
- }
745
+ } ;
737
746
} ) ;
738
747
739
748
const results : number [ ] = [ ] ;
@@ -759,7 +768,7 @@ describe('Observable', () => {
759
768
try {
760
769
for await ( const value of source ) {
761
770
results . push ( value ) ;
762
- throw new Error ( 'wee' )
771
+ throw new Error ( 'wee' ) ;
763
772
}
764
773
} catch {
765
774
// Ignore
@@ -786,7 +795,7 @@ describe('Observable', () => {
786
795
thrownError = err ;
787
796
}
788
797
789
- expect ( thrownError ?. message ) . to . equal ( 'wee' )
798
+ expect ( thrownError ?. message ) . to . equal ( 'wee' ) ;
790
799
expect ( results ) . to . deep . equal ( [ 1 , 2 ] ) ;
791
800
} ) ;
792
801
@@ -826,7 +835,7 @@ describe('Observable', () => {
826
835
expect ( results ) . to . deep . equal ( [ 1 , 2 , 3 ] ) ;
827
836
} ) ;
828
837
829
- it ( 'should handle situations where values from the observable are arriving faster than the are being consumed by the async iterator' , async ( ) => {
838
+ it ( 'should handle situations where values from the observable are arriving faster than the are being consumed by the async iterator' , async ( ) => {
830
839
const subject = new Subject < number > ( ) ;
831
840
832
841
const results : any [ ] = [ ] ;
@@ -838,7 +847,7 @@ describe('Observable', () => {
838
847
results . push ( result . value ) ;
839
848
} ) ;
840
849
subject . next ( 1 ) ;
841
- await first
850
+ await first ;
842
851
expect ( results ) . to . deep . equal ( [ 1 ] ) ;
843
852
844
853
// push values through the observable that aren't yet consumed by the async iterator
@@ -861,13 +870,9 @@ describe('Observable', () => {
861
870
const asyncIterator = subject [ Symbol . asyncIterator ] ( ) ;
862
871
863
872
// Queue up three promises, but don't await them.
864
- const allPending = Promise . all ( [
865
- asyncIterator . next ( ) ,
866
- asyncIterator . next ( ) ,
867
- asyncIterator . next ( ) ,
868
- ] ) . then ( ( allResults ) => {
869
- results . push ( ...allResults )
870
- } )
873
+ const allPending = Promise . all ( [ asyncIterator . next ( ) , asyncIterator . next ( ) , asyncIterator . next ( ) ] ) . then ( ( allResults ) => {
874
+ results . push ( ...allResults ) ;
875
+ } ) ;
871
876
872
877
expect ( results ) . to . deep . equal ( [ ] ) ;
873
878
@@ -893,7 +898,7 @@ describe('Observable', () => {
893
898
asyncIterator . next ( ) . catch ( ( err : any ) => results . push ( err ) ) ,
894
899
asyncIterator . next ( ) . catch ( ( err : any ) => results . push ( err ) ) ,
895
900
asyncIterator . next ( ) . catch ( ( err : any ) => results . push ( err ) ) ,
896
- ] )
901
+ ] ) ;
897
902
898
903
expect ( results ) . to . deep . equal ( [ ] ) ;
899
904
@@ -915,7 +920,7 @@ describe('Observable', () => {
915
920
state = 'subscribed' ;
916
921
return ( ) => {
917
922
state = 'unsubscribed' ;
918
- }
923
+ } ;
919
924
} ) ;
920
925
921
926
const asyncIterator = source [ Symbol . asyncIterator ] ( ) ;
@@ -930,10 +935,10 @@ describe('Observable', () => {
930
935
let state = 'idle' ;
931
936
const source = new Observable < number > ( ( subscriber ) => {
932
937
state = 'subscribed' ;
933
- subscriber . next ( 0 )
938
+ subscriber . next ( 0 ) ;
934
939
return ( ) => {
935
940
state = 'unsubscribed' ;
936
- }
941
+ } ;
937
942
} ) ;
938
943
939
944
const asyncIterator = source [ Symbol . asyncIterator ] ( ) ;
@@ -948,4 +953,4 @@ describe('Observable', () => {
948
953
expect ( state ) . to . equal ( 'unsubscribed' ) ;
949
954
} ) ;
950
955
} ) ;
951
- } ) ;
956
+ } ) ;
0 commit comments