##// END OF EJS Templates
updated tests
cin -
r152:956dc3113836 default
parent child
Show More
@@ -144,30 +144,48 tap.test("of(...) tests", async t => {
144 144 "of(...) should terminate with error when a parameter is rejected"
145 145 );
146 146
147 t.same(await of(1,2,3).collect(), [1,2,3], ".collect() should return the collected sequence");
148 await t.rejects(of(1,2,3).collect(cancelled), ".collect() should support cancellation");
147 t.same(await of(1, 2, 3).collect(), [1, 2, 3], ".collect() should return the collected sequence");
148 await t.rejects(of(1, 2, 3).collect(cancelled), ".collect() should support cancellation");
149 149
150 150 }).catch(() => { });
151 151
152 152 tap.test(".tap() tests", async t => {
153 153 const side: number[] = [];
154 154
155 of(1,2)
156 .tap({next: v => side.push(v), complete: () => side.push(0)})
157 .tap({next: v => side.push(v*v)})
155 of(1, 2)
156 .tap({ next: v => side.push(v), complete: () => side.push(0) })
157 .tap({ next: v => side.push(v * v) })
158 158 .subscribe({});
159 159
160 t.same(side, [1,1,2,4,0], ".tap() should be called in the order of registration");
160 t.same(side, [1, 1, 2, 4, 0], ".tap() should be called in the order of registration");
161 161
162 162 side.length = 0;
163 163
164 164 await new Promise<void>(resolve => {
165 of(1,2,delay(1).then(() => 3))
166 .tap({next: v => side.push(v)})
167 .tap({ next: v => v === 1 && resolve()})
165 of(1, 2, delay(1).then(() => 3))
166 .tap({ next: v => side.push(v) })
167 .tap({ next: v => v === 1 && resolve() })
168 168 .subscribe({});
169 169 });
170 170
171 t.same(side, [1,2], ".tap() should be processed synchronously");
171 t.same(side, [1, 2], ".tap() should be processed synchronously");
172
173 }).catch(() => { });
174
175 tap.test(".while() tests", async t => {
176
177 const seq = of(1, 2, 3, 4).while(v => v <= 2);
178
179 t.same(await seq.collect(), [1, 2], "Should collect only taken elements");
172 180
173 }).catch(() => {}); No newline at end of file
181 const data: number[] = [];
182 let complete = 0;
183 seq.subscribe({
184 next: v => data.push(v),
185 complete: () => complete++
186 });
187
188 t.same(data, [1, 2], "Should receive only taken elements");
189 t.equal(complete, 1, "Complete should run once");
190
191 }).catch(() => { }); No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now