1
1
import { expect } from 'chai' ;
2
- import * as Rx from 'rxjs/Rx';
2
+ import { Observable , partition , of } from 'rxjs' ;
3
+ import { map , mergeMap } from 'rxjs/operators' ;
3
4
import { hot , cold , expectObservable , expectSubscriptions } from '../helpers/marble-testing' ;
4
5
5
- // TODO: The imports on these tests can't be modernized until we do away with
6
- // the partition "operator" and make it a creation method.
7
6
declare function asDiagram ( arg : string ) : Function ;
8
7
9
- const Observable = Rx.Observable;
10
-
11
8
/** @test {partition} */
12
9
describe ( 'Observable.prototype.partition' , ( ) => {
13
- function expectObservableArray(result: Rx. Observable<string>[], expected: string[]) {
10
+ function expectObservableArray ( result : Observable < string > [ ] , expected : string [ ] ) {
14
11
for ( let idx = 0 ; idx < result . length ; idx ++ ) {
15
12
expectObservable ( result [ idx ] ) . toBe ( expected [ idx ] ) ;
16
13
}
@@ -23,7 +20,7 @@ describe('Observable.prototype.partition', () => {
23
20
const expected = [ '--1-----3---------5------|' ,
24
21
'----2----------4------6--|' ] ;
25
22
26
- const result = e1. partition((x: any) => x % 2 === 1);
23
+ const result = partition ( e1 , ( x : any ) => x % 2 === 1 ) ;
27
24
28
25
expectObservableArray ( result , expected ) ;
29
26
expectSubscriptions ( e1 . subscriptions ) . toBe ( [ e1subs , e1subs ] ) ;
@@ -39,7 +36,7 @@ describe('Observable.prototype.partition', () => {
39
36
return x === 'a' ;
40
37
}
41
38
42
- expectObservableArray(e1. partition(predicate), expected);
39
+ expectObservableArray ( partition ( e1 , predicate ) , expected ) ;
43
40
expectSubscriptions ( e1 . subscriptions ) . toBe ( [ e1subs , e1subs ] ) ;
44
41
} ) ;
45
42
@@ -53,7 +50,7 @@ describe('Observable.prototype.partition', () => {
53
50
return index % 2 === 0 ;
54
51
}
55
52
56
- expectObservableArray(e1. partition(predicate), expected);
53
+ expectObservableArray ( partition ( e1 , predicate ) , expected ) ;
57
54
expectSubscriptions ( e1 . subscriptions ) . toBe ( [ e1subs , e1subs ] ) ;
58
55
} ) ;
59
56
@@ -67,7 +64,7 @@ describe('Observable.prototype.partition', () => {
67
64
return x === this . value ;
68
65
}
69
66
70
- expectObservableArray(e1. partition(predicate, {value: 'a'}), expected);
67
+ expectObservableArray ( partition ( e1 , predicate , { value : 'a' } ) , expected ) ;
71
68
expectSubscriptions ( e1 . subscriptions ) . toBe ( [ e1subs , e1subs ] ) ;
72
69
} ) ;
73
70
@@ -81,7 +78,7 @@ describe('Observable.prototype.partition', () => {
81
78
return x === 'a' ;
82
79
}
83
80
84
- expectObservableArray(e1. partition(predicate), expected);
81
+ expectObservableArray ( partition ( e1 , predicate ) , expected ) ;
85
82
expectSubscriptions ( e1 . subscriptions ) . toBe ( [ e1subs , e1subs ] ) ;
86
83
} ) ;
87
84
@@ -95,7 +92,7 @@ describe('Observable.prototype.partition', () => {
95
92
return x === 'a' ;
96
93
}
97
94
98
- expectObservableArray(e1. partition(predicate), expected);
95
+ expectObservableArray ( partition ( e1 , predicate ) , expected ) ;
99
96
expectSubscriptions ( e1 . subscriptions ) . toBe ( [ e1subs , e1subs ] ) ;
100
97
} ) ;
101
98
@@ -115,7 +112,7 @@ describe('Observable.prototype.partition', () => {
115
112
return match ;
116
113
}
117
114
118
- expectObservableArray(e1. partition(predicate), expected);
115
+ expectObservableArray ( partition ( e1 , predicate ) , expected ) ;
119
116
expectSubscriptions ( e1 . subscriptions ) . toBe ( [ e1subs , e1subs ] ) ;
120
117
} ) ;
121
118
@@ -129,7 +126,7 @@ describe('Observable.prototype.partition', () => {
129
126
return x === 'x' ;
130
127
}
131
128
132
- expectObservableArray(e1. partition(predicate), expected);
129
+ expectObservableArray ( partition ( e1 , predicate ) , expected ) ;
133
130
expectSubscriptions ( e1 . subscriptions ) . toBe ( [ e1subs , e1subs ] ) ;
134
131
} ) ;
135
132
@@ -143,7 +140,7 @@ describe('Observable.prototype.partition', () => {
143
140
return x === 'x' ;
144
141
}
145
142
146
- expectObservableArray(e1. partition(predicate), expected);
143
+ expectObservableArray ( partition ( e1 , predicate ) , expected ) ;
147
144
expectSubscriptions ( e1 . subscriptions ) . toBe ( [ e1subs , e1subs ] ) ;
148
145
} ) ;
149
146
@@ -157,7 +154,7 @@ describe('Observable.prototype.partition', () => {
157
154
return x === 'a' ;
158
155
}
159
156
160
- expectObservableArray(e1. partition(predicate), expected);
157
+ expectObservableArray ( partition ( e1 , predicate ) , expected ) ;
161
158
expectSubscriptions ( e1 . subscriptions ) . toBe ( [ e1subs , e1subs ] ) ;
162
159
} ) ;
163
160
@@ -171,7 +168,7 @@ describe('Observable.prototype.partition', () => {
171
168
return x === 'a' ;
172
169
}
173
170
174
- expectObservableArray(e1. partition(predicate), expected);
171
+ expectObservableArray ( partition ( e1 , predicate ) , expected ) ;
175
172
expectSubscriptions ( e1 . subscriptions ) . toBe ( [ e1subs , e1subs ] ) ;
176
173
} ) ;
177
174
@@ -185,7 +182,7 @@ describe('Observable.prototype.partition', () => {
185
182
return x === 'a' ;
186
183
}
187
184
188
- expectObservableArray(e1. partition(predicate), expected);
185
+ expectObservableArray ( partition ( e1 , predicate ) , expected ) ;
189
186
expectSubscriptions ( e1 . subscriptions ) . toBe ( [ e1subs , e1subs ] ) ;
190
187
} ) ;
191
188
@@ -199,7 +196,7 @@ describe('Observable.prototype.partition', () => {
199
196
return x === 'a' ;
200
197
}
201
198
202
- expectObservableArray(e1. partition(predicate), expected);
199
+ expectObservableArray ( partition ( e1 , predicate ) , expected ) ;
203
200
expectSubscriptions ( e1 . subscriptions ) . toBe ( [ e1subs , e1subs ] ) ;
204
201
} ) ;
205
202
@@ -213,7 +210,7 @@ describe('Observable.prototype.partition', () => {
213
210
return x === 'a' ;
214
211
}
215
212
216
- expectObservableArray(e1. partition(predicate), expected);
213
+ expectObservableArray ( partition ( e1 , predicate ) , expected ) ;
217
214
expectSubscriptions ( e1 . subscriptions ) . toBe ( [ e1subs , e1subs ] ) ;
218
215
} ) ;
219
216
@@ -227,7 +224,7 @@ describe('Observable.prototype.partition', () => {
227
224
function predicate ( x : string ) {
228
225
return x === 'a' ;
229
226
}
230
- const result = e1. partition(predicate);
227
+ const result = partition ( e1 , predicate ) ;
231
228
232
229
for ( let idx = 0 ; idx < result . length ; idx ++ ) {
233
230
expectObservable ( result [ idx ] , unsub ) . toBe ( expected [ idx ] ) ;
@@ -242,11 +239,10 @@ describe('Observable.prototype.partition', () => {
242
239
'----b--- ' ] ;
243
240
const unsub = ' ! ' ;
244
241
245
- const result = e1
246
- .mergeMap((x: string) => Observable.of(x))
247
- .partition((x: string) => x === 'a')
248
- .map((observable: Rx.Observable<string>) =>
249
- observable.mergeMap((x: string) => Observable.of(x)));
242
+ const e1Pipe = e1 . pipe (
243
+ mergeMap ( ( x : string ) => of ( x ) )
244
+ ) ;
245
+ const result = partition ( e1Pipe , ( x : string ) => x === 'a' ) ;
250
246
251
247
expectObservable ( result [ 0 ] , unsub ) . toBe ( expected [ 0 ] ) ;
252
248
expectObservable ( result [ 1 ] , unsub ) . toBe ( expected [ 1 ] ) ;
@@ -256,10 +252,10 @@ describe('Observable.prototype.partition', () => {
256
252
it ( 'should accept thisArg' , ( ) => {
257
253
const thisArg = { } ;
258
254
259
- Observable. of(1).partition( function (this: any, value: number) {
255
+ partition ( of ( 1 ) , function ( this : any , value : number ) {
260
256
expect ( this ) . to . deep . equal ( thisArg ) ;
261
257
return true ;
262
258
} , thisArg )
263
- .forEach((observable: Rx. Observable<number>) => observable.subscribe());
259
+ . forEach ( ( observable : Observable < number > ) => observable . subscribe ( ) ) ;
264
260
} ) ;
265
261
} ) ;
0 commit comments