# HG changeset patch # User cin # Date 2023-09-24 12:13:03 # Node ID 956dc31138360a0dcdd33bc298dafd0d00c3dadd # Parent d004becd2e654de09a393948e281934733eb37aa updated tests diff --git a/djx/src/test/ts/observable-tests.ts b/djx/src/test/ts/observable-tests.ts --- a/djx/src/test/ts/observable-tests.ts +++ b/djx/src/test/ts/observable-tests.ts @@ -144,30 +144,48 @@ tap.test("of(...) tests", async t => { "of(...) should terminate with error when a parameter is rejected" ); - t.same(await of(1,2,3).collect(), [1,2,3], ".collect() should return the collected sequence"); - await t.rejects(of(1,2,3).collect(cancelled), ".collect() should support cancellation"); + t.same(await of(1, 2, 3).collect(), [1, 2, 3], ".collect() should return the collected sequence"); + await t.rejects(of(1, 2, 3).collect(cancelled), ".collect() should support cancellation"); }).catch(() => { }); tap.test(".tap() tests", async t => { const side: number[] = []; - of(1,2) - .tap({next: v => side.push(v), complete: () => side.push(0)}) - .tap({next: v => side.push(v*v)}) + of(1, 2) + .tap({ next: v => side.push(v), complete: () => side.push(0) }) + .tap({ next: v => side.push(v * v) }) .subscribe({}); - t.same(side, [1,1,2,4,0], ".tap() should be called in the order of registration"); + t.same(side, [1, 1, 2, 4, 0], ".tap() should be called in the order of registration"); side.length = 0; await new Promise(resolve => { - of(1,2,delay(1).then(() => 3)) - .tap({next: v => side.push(v)}) - .tap({ next: v => v === 1 && resolve()}) + of(1, 2, delay(1).then(() => 3)) + .tap({ next: v => side.push(v) }) + .tap({ next: v => v === 1 && resolve() }) .subscribe({}); }); - t.same(side, [1,2], ".tap() should be processed synchronously"); + t.same(side, [1, 2], ".tap() should be processed synchronously"); + +}).catch(() => { }); + +tap.test(".while() tests", async t => { + + const seq = of(1, 2, 3, 4).while(v => v <= 2); + + t.same(await seq.collect(), [1, 2], "Should collect only taken elements"); -}).catch(() => {}); \ No newline at end of file + const data: number[] = []; + let complete = 0; + seq.subscribe({ + next: v => data.push(v), + complete: () => complete++ + }); + + t.same(data, [1, 2], "Should receive only taken elements"); + t.equal(complete, 1, "Complete should run once"); + +}).catch(() => { }); \ No newline at end of file