Skip to content

Commit dc89736

Browse files
authored
feat(concatWith): adds concatWith (#4988)
`concat` operator, not the `concat` static function, is now deprecated, but in favor of `concatWith`. NOTE: First real usage of `TestScheduler` run mode in library. Enabled me to format the document with Prettier :)
1 parent 865b7d3 commit dc89736

File tree

8 files changed

+519
-40
lines changed

8 files changed

+519
-40
lines changed

spec-dtslint/helpers.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,24 @@ export class H { h = 0; }
1111
export class I { i = 0; }
1212
export class J { j = 0; }
1313

14-
export const a = of(new A());
15-
export const b = of(new B());
16-
export const c = of(new C());
17-
export const d = of(new D());
18-
export const e = of(new E());
19-
export const f = of(new F());
20-
export const g = of(new G());
21-
export const h = of(new H());
22-
export const i = of(new I());
23-
export const j = of(new J());
14+
export const a = new A();
15+
export const b = new B();
16+
export const c = new C();
17+
export const d = new D();
18+
export const e = new E();
19+
export const f = new F();
20+
export const g = new G();
21+
export const h = new H();
22+
export const i = new I();
23+
export const j = new J();
24+
25+
export const a$ = of(new A());
26+
export const b$ = of(new B());
27+
export const c$ = of(new C());
28+
export const d$ = of(new D());
29+
export const e$ = of(new E());
30+
export const f$ = of(new F());
31+
export const g$ = of(new G());
32+
export const h$ = of(new H());
33+
export const i$ = of(new I());
34+
export const j$ = of(new J());
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { of } from 'rxjs';
2+
import { concatWith } from 'rxjs/operators';
3+
import { a, b$, c$, d$, e$ } from 'helpers';
4+
5+
it('should support rest params', () => {
6+
const arr = [b$, c$];
7+
const o = of(a).pipe(concatWith(...arr)); // $ExpectType Observable<A | B | C>
8+
const o2 = of(a).pipe(concatWith(d$, ...arr, e$)); // $ExpectType Observable<A | B | C | D | E>
9+
});
10+
11+
it('should infer correctly', () => {
12+
const o = of(1, 2, 3).pipe(concatWith()); // $ExpectType Observable<number>
13+
});
14+
15+
it('should support one argument', () => {
16+
const o = of(1, 2, 3).pipe(concatWith(of(1))); // $ExpectType Observable<number>
17+
});
18+
19+
it('should support two arguments', () => {
20+
const o = of(1, 2, 3).pipe(concatWith(of(1), of(2))); // $ExpectType Observable<number>
21+
});
22+
23+
it('should support three arguments', () => {
24+
const o = of(1, 2, 3).pipe(concatWith(of(1), of(2), of(3))); // $ExpectType Observable<number>
25+
});
26+
27+
it('should support four arguments', () => {
28+
const o = of(1, 2, 3).pipe(concatWith(of(1), of(2), of(3), of(4))); // $ExpectType Observable<number>
29+
});
30+
31+
it('should support five arguments', () => {
32+
const o = of(1, 2, 3).pipe(concatWith(of(1), of(2), of(3), of(4), of(5))); // $ExpectType Observable<number>
33+
});
34+
35+
it('should support six arguments', () => {
36+
const o = of(1, 2, 3).pipe(concatWith(of(1), of(2), of(3), of(4), of(5), of(6))); // $ExpectType Observable<number>
37+
});
38+
39+
it('should support six or more arguments', () => {
40+
const o = of(1, 2, 3).pipe(concatWith(of(1), of(2), of(3), of(4), of(5), of(6), of(7), of(8), of(9))); // $ExpectType Observable<number>
41+
});
42+
43+
it('should support promises', () => {
44+
const o = of(1, 2, 3).pipe(concatWith(Promise.resolve(4))); // $ExpectType Observable<number>
45+
});
46+
47+
it('should support arrays', () => {
48+
const o = of(1, 2, 3).pipe(concatWith([4, 5])); // $ExpectType Observable<number>
49+
});
50+
51+
it('should support iterables', () => {
52+
const o = of(1, 2, 3).pipe(concatWith('foo')); // $ExpectType Observable<string | number>
53+
});
54+
55+
it('should infer correctly with multiple types', () => {
56+
const o = of(1, 2, 3).pipe(concatWith(of('foo'), Promise.resolve([1]), of(6))); // $ExpectType Observable<string | number | number[]>
57+
});
58+
59+
it('should enforce types', () => {
60+
const o = of(1, 2, 3).pipe(concatWith(5)); // $ExpectError
61+
const p = of(1, 2, 3).pipe(concatWith(of(5), 6)); // $ExpectError
62+
});

spec-dtslint/operators/merge-spec.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,81 @@
1-
import { of, asyncScheduler } from 'rxjs';
1+
import { asyncScheduler } from 'rxjs';
22
import { merge } from 'rxjs/operators';
3-
import { A, B, C, D, E, F, G, a, b, c, d, e, f, g } from '../helpers';
3+
import { a$, b$, c$, d$, e$, f$} from '../helpers';
44

55
it('should accept no parameter', () => {
6-
const res = a.pipe(merge()); // $ExpectType Observable<A>
6+
const res = a$.pipe(merge()); // $ExpectType Observable<A>
77
});
88

99
it('should infer correctly with scheduler param', () => {
10-
const res = a.pipe(merge(asyncScheduler)); // $ExpectType Observable<A>
10+
const res = a$.pipe(merge(asyncScheduler)); // $ExpectType Observable<A>
1111
});
1212

1313
it('should infer correctly with concurrent param', () => {
14-
const res = a.pipe(merge(3)); // $ExpectType Observable<A>
14+
const res = a$.pipe(merge(3)); // $ExpectType Observable<A>
1515
});
1616

1717
it('should infer correctly with concurrent and scheduler param', () => {
18-
const res = a.pipe(merge(3, asyncScheduler)); // $ExpectType Observable<A>
18+
const res = a$.pipe(merge(3, asyncScheduler)); // $ExpectType Observable<A>
1919
});
2020

2121
it('should infer correctly with 1 Observable param', () => {
22-
const res = a.pipe(merge(b)); // $ExpectType Observable<A | B>
22+
const res = a$.pipe(merge(b$)); // $ExpectType Observable<A | B>
2323
});
2424

2525
it('should infer correctly with 2 Observable param', () => {
26-
const res = a.pipe(merge(b, c)); // $ExpectType Observable<A | B | C>
26+
const res = a$.pipe(merge(b$, c$)); // $ExpectType Observable<A | B | C>
2727
});
2828

2929
it('should infer correctly with 3 Observable param', () => {
30-
const res = a.pipe(merge(b, c, d)); // $ExpectType Observable<A | B | C | D>
30+
const res = a$.pipe(merge(b$, c$, d$)); // $ExpectType Observable<A | B | C | D>
3131
});
3232

3333
it('should infer correctly with 4 Observable param', () => {
34-
const res = a.pipe(merge(b, c, d, e)); // $ExpectType Observable<A | B | C | D | E>
34+
const res = a$.pipe(merge(b$, c$, d$, e$)); // $ExpectType Observable<A | B | C | D | E>
3535
});
3636

3737
it('should infer correctly with 5 Observable param', () => {
38-
const res = a.pipe(merge(b, c, d, e, f)); // $ExpectType Observable<A | B | C | D | E | F>
38+
const res = a$.pipe(merge(b$, c$, d$, e$, f$)); // $ExpectType Observable<A | B | C | D | E | F>
3939
});
4040

4141
it('should infer correctly with 1 Observable and concurrent param', () => {
42-
const res = a.pipe(merge(b, 1)); // $ExpectType Observable<A | B>
42+
const res = a$.pipe(merge(b$, 1)); // $ExpectType Observable<A | B>
4343
});
4444

4545
it('should infer correctly with 2 Observable and concurrent param', () => {
46-
const res = a.pipe(merge(b, c, 1)); // $ExpectType Observable<A | B | C>
46+
const res = a$.pipe(merge(b$, c$, 1)); // $ExpectType Observable<A | B | C>
4747
});
4848

4949
it('should infer correctly with 3 Observable and concurrent param', () => {
50-
const res = a.pipe(merge(b, c, d, 1)); // $ExpectType Observable<A | B | C | D>
50+
const res = a$.pipe(merge(b$, c$, d$, 1)); // $ExpectType Observable<A | B | C | D>
5151
});
5252

5353
it('should infer correctly with 4 Observable and concurrent param', () => {
54-
const res = a.pipe(merge(b, c, d, e, 1)); // $ExpectType Observable<A | B | C | D | E>
54+
const res = a$.pipe(merge(b$, c$, d$, e$, 1)); // $ExpectType Observable<A | B | C | D | E>
5555
});
5656

5757
it('should infer correctly with 5 Observable and concurrent param', () => {
58-
const res = a.pipe(merge(b, c, d, e, f, 1)); // $ExpectType Observable<A | B | C | D | E | F>
58+
const res = a$.pipe(merge(b$, c$, d$, e$, f$, 1)); // $ExpectType Observable<A | B | C | D | E | F>
5959
});
6060

6161
it('should infer correctly with 1 Observable, concurrent, and scheduler param', () => {
62-
const res = a.pipe(merge(b, 1, asyncScheduler)); // $ExpectType Observable<A | B>
62+
const res = a$.pipe(merge(b$, 1, asyncScheduler)); // $ExpectType Observable<A | B>
6363
});
6464

6565
it('should infer correctly with 2 Observable, concurrent, and scheduler param', () => {
66-
const res = a.pipe(merge(b, c, 1, asyncScheduler)); // $ExpectType Observable<A | B | C>
66+
const res = a$.pipe(merge(b$, c$, 1, asyncScheduler)); // $ExpectType Observable<A | B | C>
6767
});
6868

6969
it('should infer correctly with 3 Observable, concurrent, and scheduler param', () => {
70-
const res = a.pipe(merge(b, c, d, 1, asyncScheduler)); // $ExpectType Observable<A | B | C | D>
70+
const res = a$.pipe(merge(b$, c$, d$, 1, asyncScheduler)); // $ExpectType Observable<A | B | C | D>
7171
});
7272

7373
it('should infer correctly with 4 Observable, concurrent, and scheduler param', () => {
74-
const res = a.pipe(merge(b, c, d, e, 1, asyncScheduler)); // $ExpectType Observable<A | B | C | D | E>
74+
const res = a$.pipe(merge(b$, c$, d$, e$, 1, asyncScheduler)); // $ExpectType Observable<A | B | C | D | E>
7575
});
7676

7777
it('should infer correctly with 5 Observable, concurrent, and scheduler param', () => {
78-
const res = a.pipe(merge(b, c, d, e, f, 1, asyncScheduler)); // $ExpectType Observable<A | B | C | D | E | F>
78+
const res = a$.pipe(merge(b$, c$, d$, e$, f$, 1, asyncScheduler)); // $ExpectType Observable<A | B | C | D | E | F>
7979
});
8080

8181
// TODO: Fix this when the both merge operator and merge creator function has been fix

spec/helpers/test-helper.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { root } from 'rxjs/internal/util/root';
55
import { observable } from 'rxjs/internal/symbol/observable';
66
import { iterator } from 'rxjs/internal/symbol/iterator';
77
import * as sinon from 'sinon';
8+
import { expect } from 'chai';
89

910
export function lowerCaseO<T>(...args: Array<any>): Observable<T> {
1011
const o = {
@@ -47,6 +48,21 @@ export const createObservableInputs = <T>(value: T) => of(
4748
} as any
4849
) as Observable<ObservableInput<T>>;
4950

51+
/**
52+
* Used to signify no subscriptions took place to `expectSubscriptions` assertions.
53+
*/
54+
export const NO_SUBS: string[] = [];
55+
56+
/**
57+
* Does a deep equality assertion. Used to set up {@link TestScheduler}, so that
58+
* trees of marbles can be compared.
59+
* @param actual The value to run the expectation against.
60+
* @param expected The value expected.
61+
*/
62+
export function assertDeepEquals (actual: any, expected: any) {
63+
expect(actual).to.deep.equal(expected);
64+
}
65+
5066
global.__root__ = root;
5167

5268
let _raf: any;

0 commit comments

Comments
 (0)