This repository has been archived by the owner on Apr 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathpluck.js
107 lines (90 loc) · 2.67 KB
/
pluck.js
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
(function () {
'use strict';
/* jshint undef: true, unused: true */
/* globals QUnit, test, Rx */
QUnit.module('pluck');
var TestScheduler = Rx.TestScheduler,
onNext = Rx.ReactiveTest.onNext,
onError = Rx.ReactiveTest.onError,
onCompleted = Rx.ReactiveTest.onCompleted,
subscribe = Rx.ReactiveTest.subscribe;
test('pluck completed', function () {
var scheduler = new TestScheduler();
var xs = scheduler.createHotObservable(
onNext(180, {prop: 1}),
onNext(210, {prop: 2}),
onNext(240, {prop: 3}),
onNext(290, {prop: 4}),
onNext(350, {prop: 5}),
onCompleted(400),
onNext(410, {prop: -1}),
onCompleted(420),
onError(430, new Error('ex'))
);
var results = scheduler.startScheduler(function () {
return xs.pluck('prop');
});
results.messages.assertEqual(
onNext(210, 2),
onNext(240, 3),
onNext(290, 4),
onNext(350, 5),
onCompleted(400)
);
xs.subscriptions.assertEqual(
subscribe(200, 400)
);
});
test('deep pluck nested completed', function () {
var scheduler = new TestScheduler();
var xs = scheduler.createHotObservable(
onNext(180, {a: {b: {c: 1}}}),
onNext(210, {a: {b: {c: 2}}}),
onNext(240, {a: {b: {c: 3}}}),
onNext(290, {a: {b: {c: 4}}}),
onNext(350, {a: {b: {c: 5}}}),
onCompleted(400),
onNext(410, {a: {b: {c: -1}}}),
onCompleted(420),
onError(430, new Error('ex'))
);
var results = scheduler.startScheduler(function () {
return xs.pluck('a', 'b', 'c');
});
results.messages.assertEqual(
onNext(210, 2),
onNext(240, 3),
onNext(290, 4),
onNext(350, 5),
onCompleted(400)
);
xs.subscriptions.assertEqual(subscribe(200, 400));
});
test('deep pluck nested edge cases', function () {
var scheduler = new TestScheduler();
var xs = scheduler.createHotObservable(
onNext(180, {a: {b: {c: 1}}}),
onNext(210, {a: {b: 2}}),
onNext(240, {a: {c: {c: 3}}}),
onNext(290, {}),
onNext(350, {a: {b: {c: 5}}}),
onCompleted(400),
onNext(410, {a: {b: {c: -1}}}),
onCompleted(420),
onError(430, new Error('ex'))
);
var results = scheduler.startScheduler(function () {
return xs.pluck('a', 'b', 'c');
});
results.messages.assertEqual(
onNext(210, undefined),
onNext(240, undefined),
onNext(290, undefined),
onNext(350, 5),
onCompleted(400)
);
xs.subscriptions.assertEqual(
subscribe(200, 400)
);
});
}());