/
pluck-spec.ts
58 lines (45 loc) · 2.07 KB
/
pluck-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
import { of } from 'rxjs';
import { pluck } from 'rxjs/operators';
it('should infer correctly', () => {
const a = of({ name: 'abc' }).pipe(pluck('name')); // $ExpectType Observable<string>
});
it('should support nested object of 2 layer depth', () => {
const a = of({ a: { name: 'abc' } }).pipe(pluck('a', 'name')); // $ExpectType Observable<string>
});
it('should support nested object of 3 layer depth', () => {
const a = of({ a: { b: { name: 'abc' } } }).pipe(pluck('a', 'b', 'name')); // $ExpectType Observable<string>
});
it('should support nested object of 4 layer depth', () => {
const a = of({ a: { b: { c: { name: 'abc' } } } }).pipe(pluck('a', 'b', 'c', 'name')); // $ExpectType Observable<string>
});
it('should support nested object of 5 layer depth', () => {
const a = of({ a: { b: { c: { d: { name: 'abc' } } } } }).pipe(pluck('a', 'b', 'c', 'd', 'name')); // $ExpectType Observable<string>
});
it('should support nested object of 6 layer depth', () => {
const a = of({ a: { b: { c: { d: { e: { name: 'abc' } } } } } }).pipe(pluck('a', 'b', 'c', 'd', 'e', 'name')); // $ExpectType Observable<string>
});
it('should support nested object of more than 6 layer depth', () => {
const a = of({ a: { b: { c: { d: { e: { f: { name: 'abc' } } } } } } }).pipe(pluck('a', 'b', 'c', 'd', 'e', 'f', 'name')); // $ExpectType Observable<unknown>
});
it('should accept existing keys only', () => {
const a = of({ name: 'abc' }).pipe(pluck('xyz')); // $ExpectType Observable<unknown>
});
it('should not accept empty parameter', () => {
const a = of({ name: 'abc' }).pipe(pluck()); // $ExpectType Observable<unknown>
});
it('should accept string only', () => {
const a = of({ name: 'abc' }).pipe(pluck(1)); // $ExpectError
});
it('should accept a spread of arguments', () => {
const obj = {
foo: {
bar: {
baz: 123
}
}
};
const path = ['foo', 'bar', 'baz'];
const a = of(obj).pipe(pluck(...path)); // $ExpectType Observable<unknown>
const path2 = ['bar', 'baz'];
const b = of(obj).pipe(pluck('foo', ...path2)); // $ExpectType Observable<unknown>
});