@@ -144,30 +144,48 tap.test("of(...) tests", async t => { | |||||
144 | "of(...) should terminate with error when a parameter is rejected" |
|
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"); |
|
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"); |
|
148 | await t.rejects(of(1, 2, 3).collect(cancelled), ".collect() should support cancellation"); | |
149 |
|
149 | |||
150 | }).catch(() => { }); |
|
150 | }).catch(() => { }); | |
151 |
|
151 | |||
152 | tap.test(".tap() tests", async t => { |
|
152 | tap.test(".tap() tests", async t => { | |
153 | const side: number[] = []; |
|
153 | const side: number[] = []; | |
154 |
|
154 | |||
155 | of(1,2) |
|
155 | of(1, 2) | |
156 | .tap({next: v => side.push(v), complete: () => side.push(0)}) |
|
156 | .tap({ next: v => side.push(v), complete: () => side.push(0) }) | |
157 | .tap({next: v => side.push(v*v)}) |
|
157 | .tap({ next: v => side.push(v * v) }) | |
158 | .subscribe({}); |
|
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 | side.length = 0; |
|
162 | side.length = 0; | |
163 |
|
163 | |||
164 | await new Promise<void>(resolve => { |
|
164 | await new Promise<void>(resolve => { | |
165 | of(1,2,delay(1).then(() => 3)) |
|
165 | of(1, 2, delay(1).then(() => 3)) | |
166 | .tap({next: v => side.push(v)}) |
|
166 | .tap({ next: v => side.push(v) }) | |
167 | .tap({ next: v => v === 1 && resolve()}) |
|
167 | .tap({ next: v => v === 1 && resolve() }) | |
168 | .subscribe({}); |
|
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