1
+ /* globals describe, it, expect, expectObservable, hot, cold */
2
+ var Rx = require ( '../../dist/cjs/Rx' ) ;
3
+
4
+ describe ( 'Observable.prototype.concat()' , function ( ) {
5
+ it ( 'should complete without emit if both sources are empty' , function ( ) {
6
+ var e1 = hot ( '--|' ) ;
7
+ var e2 = hot ( '----|' ) ;
8
+ var expected = '----|' ;
9
+
10
+ expectObservable ( e1 . concat ( e2 ) ) . toBe ( expected ) ;
11
+ } ) ;
12
+
13
+ it ( 'should not complete if first source does not completes' , function ( ) {
14
+ var e1 = hot ( '-' ) ;
15
+ var e2 = hot ( '--|' ) ;
16
+ var expected = '-' ;
17
+
18
+ expectObservable ( e1 . concat ( e2 ) ) . toBe ( expected ) ;
19
+ } ) ;
20
+
21
+ it ( 'should not complete if second source does not completes' , function ( ) {
22
+ var e1 = hot ( '--|' ) ;
23
+ var e2 = hot ( '-' ) ;
24
+ var expected = '-' ;
25
+
26
+ expectObservable ( e1 . concat ( e2 ) ) . toBe ( expected ) ;
27
+ } ) ;
28
+
29
+ it ( 'should not complete if both sources do not complete' , function ( ) {
30
+ var e1 = hot ( '-' ) ;
31
+ var e2 = hot ( '-' ) ;
32
+ var expected = '-' ;
33
+
34
+ expectObservable ( e1 . concat ( e2 ) ) . toBe ( expected ) ;
35
+ } ) ;
36
+
37
+ it ( 'should raise error when first source is empty, second source raises error' , function ( ) {
38
+ var e1 = hot ( '--|' ) ;
39
+ var e2 = hot ( '----#' ) ;
40
+ var expected = '----#' ;
41
+
42
+ expectObservable ( e1 . concat ( e2 ) ) . toBe ( expected ) ;
43
+ } ) ;
44
+
45
+ it ( 'should raise error when first source raises error, second source is empty' , function ( ) {
46
+ var e1 = hot ( '---#' ) ;
47
+ var e2 = hot ( '----|' ) ;
48
+ var expected = '---#' ;
49
+
50
+ expectObservable ( e1 . concat ( e2 ) ) . toBe ( expected ) ;
51
+ } ) ;
52
+
53
+ it ( 'should raise first error when both source raise error' , function ( ) {
54
+ var e1 = hot ( '---#' ) ;
55
+ var e2 = hot ( '------#' ) ;
56
+ var expected = '---#' ;
57
+
58
+ expectObservable ( e1 . concat ( e2 ) ) . toBe ( expected ) ;
59
+ } ) ;
60
+
61
+ it ( 'should concat if first source emits once, second source is empty' , function ( ) {
62
+ var e1 = hot ( '--a--|' ) ;
63
+ var e2 = hot ( '--------|' ) ;
64
+ var expected = '--a-----|' ;
65
+
66
+ expectObservable ( e1 . concat ( e2 ) ) . toBe ( expected ) ;
67
+ } ) ;
68
+
69
+ it ( 'should concat if first source is empty, second source emits once' , function ( ) {
70
+ var e1 = hot ( '--|' ) ;
71
+ var e2 = hot ( '--a--|' ) ;
72
+ var expected = '--a--|' ;
73
+
74
+ expectObservable ( e1 . concat ( e2 ) ) . toBe ( expected ) ;
75
+ } ) ;
76
+
77
+ it ( 'should emit element from first source, and should not complete if second source does not completes' , function ( ) {
78
+ var e1 = hot ( '--a--|' ) ;
79
+ var e2 = hot ( '-' ) ;
80
+ var expected = '--a-' ;
81
+
82
+ expectObservable ( e1 . concat ( e2 ) ) . toBe ( expected ) ;
83
+ } ) ;
84
+
85
+ it ( 'should not complete if first source does not complete' , function ( ) {
86
+ var e1 = hot ( '-' ) ;
87
+ var e2 = hot ( '--a--|' ) ;
88
+ var expected = '-' ;
89
+
90
+ expectObservable ( e1 . concat ( e2 ) ) . toBe ( expected ) ;
91
+ } ) ;
92
+
93
+ it ( 'should emit elements from each source when source emit once' , function ( ) {
94
+ var e1 = hot ( '---a|' ) ;
95
+ var e2 = hot ( '-----b--|' ) ;
96
+ var expected = '---a-b--|' ;
97
+
98
+ expectObservable ( e1 . concat ( e2 ) ) . toBe ( expected ) ;
99
+ } ) ;
100
+
101
+ it ( 'should raise error from first source and does not emit from second source' , function ( ) {
102
+ var e1 = hot ( '--#' ) ;
103
+ var e2 = hot ( '----a--|' ) ;
104
+ var expected = '--#' ;
105
+
106
+ expectObservable ( e1 . concat ( e2 ) ) . toBe ( expected ) ;
107
+ } ) ;
108
+
109
+ it ( 'should emit element from first source then raise error from second source' , function ( ) {
110
+ var e1 = hot ( '--a--|' ) ;
111
+ var e2 = hot ( '-------#' ) ;
112
+ var expected = '--a----#' ;
113
+
114
+ expectObservable ( e1 . concat ( e2 ) ) . toBe ( expected ) ;
115
+ } ) ;
116
+
117
+ it ( 'should emit all elements from both hot observable source if first source complets before second source starts emit' , function ( ) {
118
+ var e1 = hot ( '--a--b-|' ) ;
119
+ var e2 = hot ( '--------x--y--|' ) ;
120
+ var expected = '--a--b--x--y--|' ;
121
+
122
+ expectObservable ( e1 . concat ( e2 ) ) . toBe ( expected ) ;
123
+ } ) ;
124
+
125
+ it ( 'should emit elements from second source regardless of completion time when second source is cold observable' , function ( ) {
126
+ var e1 = hot ( '--a--b--c---|' ) ;
127
+ var e2 = cold ( '-x-y-z-|' ) ;
128
+ var expected = '--a--b--c----x-y-z-|' ;
129
+
130
+ expectObservable ( e1 . concat ( e2 ) ) . toBe ( expected ) ;
131
+ } ) ;
132
+
133
+ it ( 'should not emit collapsing element from second source' , function ( ) {
134
+ var e1 = hot ( '--a--b--c--|' ) ;
135
+ var e2 = hot ( '--------x--y--z--|' ) ;
136
+ var expected = '--a--b--c--y--z--|' ;
137
+
138
+ expectObservable ( e1 . concat ( e2 ) ) . toBe ( expected ) ;
139
+ } ) ;
140
+ } ) ;
0 commit comments