forked from ReactiveX/rxjs
/
combineLatest-spec.ts
154 lines (117 loc) · 5.8 KB
/
combineLatest-spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import { combineLatest } from 'rxjs';
import { a$, b$, c$, d$, e$, f$, g$, A, B, C, D, E, F } from '../helpers';
it('should accept 1 param', () => {
const o = combineLatest(a$); // $ExpectType Observable<[A]>
});
it('should accept 2 params', () => {
const o = combineLatest(a$, b$); // $ExpectType Observable<[A, B]>
});
it('should accept 3 params', () => {
const o = combineLatest(a$, b$, c$); // $ExpectType Observable<[A, B, C]>
});
it('should accept 4 params', () => {
const o = combineLatest(a$, b$, c$, d$); // $ExpectType Observable<[A, B, C, D]>
});
it('should accept 5 params', () => {
const o = combineLatest(a$, b$, c$, d$, e$); // $ExpectType Observable<[A, B, C, D, E]>
});
it('should accept 6 params', () => {
const o = combineLatest(a$, b$, c$, d$, e$, f$); // $ExpectType Observable<[A, B, C, D, E, F]>
});
it('should result in Observable<unknown> for 7 or more params', () => {
const o = combineLatest(a$, b$, c$, d$, e$, f$, g$); // $ExpectType Observable<[A, B, C, D, E, F, G]>
});
it('should accept union types', () => {
const u1: typeof a$ | typeof b$ = Math.random() > 0.5 ? a$ : b$;
const u2: typeof c$ | typeof d$ = Math.random() > 0.5 ? c$ : d$;
const o = combineLatest(u1, u2); // $ExpectType Observable<[A | B, C | D]>
});
it('should accept 1 param and a result selector', () => {
const o = combineLatest(a$, (...values) => new A()); // $ExpectType Observable<A>
});
it('should accept 2 params and a result selector', () => {
const o = combineLatest(a$, b$, (...values) => new A()); // $ExpectType Observable<A>
});
it('should accept 3 params and a result selector', () => {
const o = combineLatest(a$, b$, c$, (...values) => new A()); // $ExpectType Observable<A>
});
it('should accept 4 params and a result selector', () => {
const o = combineLatest(a$, b$, c$, d$, (...values) => new A()); // $ExpectType Observable<A>
});
it('should accept 5 params and a result selector', () => {
const o = combineLatest(a$, b$, c$, d$, e$, (...values) => new A()); // $ExpectType Observable<A>
});
it('should accept 6 params and a result selector', () => {
const o = combineLatest(a$, b$, c$, d$, e$, f$, (...values) => new A()); // $ExpectType Observable<A>
});
it('should accept 7 or more params and a result selector', () => {
const o = combineLatest(a$, b$, c$, d$, e$, f$, g$, g$, g$, (...values) => new A()); // $ExpectType Observable<A>
});
it('should accept 1 param', () => {
const o = combineLatest([a$]); // $ExpectType Observable<[A]>
});
it('should accept 2 params', () => {
const o = combineLatest([a$, b$]); // $ExpectType Observable<[A, B]>
});
it('should accept 3 params', () => {
const o = combineLatest([a$, b$, c$]); // $ExpectType Observable<[A, B, C]>
});
it('should accept 4 params', () => {
const o = combineLatest([a$, b$, c$, d$]); // $ExpectType Observable<[A, B, C, D]>
});
it('should accept 5 params', () => {
const o = combineLatest([a$, b$, c$, d$, e$]); // $ExpectType Observable<[A, B, C, D, E]>
});
it('should accept 6 params', () => {
const o = combineLatest([a$, b$, c$, d$, e$, f$]); // $ExpectType Observable<[A, B, C, D, E, F]>
});
it('should have basic support for 7 or more params', () => {
const o = combineLatest([a$, b$, c$, d$, e$, f$, g$]); // $ExpectType Observable<[A, B, C, D, E, F, G]>
});
it('should have full support for 7 or more params with readonly tuples', () => {
const o = combineLatest([a$, b$, c$, d$, e$, f$, g$] as const); // $ExpectType Observable<[A, B, C, D, E, F, G]>
});
it('should handle an array of Observables', () => {
const o = combineLatest([a$, a$, a$, a$, a$, a$, a$, a$, a$, a$, a$]); // $ExpectType Observable<[A, A, A, A, A, A, A, A, A, A, A]>
});
it('should accept 1 param and a result selector', () => {
const o = combineLatest([a$], (a: A) => new A()); // $ExpectType Observable<A>
});
it('should accept 2 params and a result selector', () => {
const o = combineLatest([a$, b$], (a: A, b: B) => new A()); // $ExpectType Observable<A>
});
it('should accept 3 params and a result selector', () => {
const o = combineLatest([a$, b$, c$], (a: A, b: B, c: C) => new A()); // $ExpectType Observable<A>
});
it('should accept 4 params and a result selector', () => {
const o = combineLatest([a$, b$, c$, d$], (a: A, b: B, c: C, d: D) => new A()); // $ExpectType Observable<A>
});
it('should accept 5 params and a result selector', () => {
const o = combineLatest([a$, b$, c$, d$, e$], (a: A, b: B, c: C, d: D, e: E) => new A()); // $ExpectType Observable<A>
});
it('should accept 6 params and a result selector', () => {
const o = combineLatest([a$, b$, c$, d$, e$, f$], (a: A, b: B, c: C, d: D, e: E, f: F) => new A()); // $ExpectType Observable<A>
});
it('should accept 7 or more params and a result selector', () => {
const o = combineLatest([a$, b$, c$, d$, e$, f$, g$, g$, g$], (a: any, b: any, c: any, d: any, e: any, f: any, g1: any, g2: any, g3: any) => new A()); // $ExpectType Observable<A>
});
describe('combineLatest({})', () => {
it('should properly type empty objects', () => {
const res = combineLatest({}); // $ExpectType Observable<never>
});
it('should work for the simple case', () => {
const res = combineLatest({ foo: a$, bar: b$, baz: c$ }); // $ExpectType Observable<{ foo: A; bar: B; baz: C; }>
});
it('should not rely upon the excess-properties behavior to identify empty objects', () => {
const obj = { foo: a$, bar: b$, baz: c$ };
const res = combineLatest(obj); // $ExpectType Observable<{ foo: A; bar: B; baz: C; }>
});
it('should reject non-ObservableInput values', () => {
const obj = { answer: 42 };
const res = combineLatest(obj); // $ExpectError
});
});
it('should take in any and return Observable<unknown> because we do not know if it is an array or object', () => {
const arg: any = null;
const res = combineLatest(arg); // $ExpectType Observable<unknown>
});