Skip to content

Commit cabb67e

Browse files
committed
Add tests for flow.once()
1 parent 7119528 commit cabb67e

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

test/flow/once/finish-pipeline.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { Flow } = self.yozo;
2+
const flow = new Flow();
3+
let resolve
4+
const promise = new Promise((...args) => resolve = args[0])
5+
let stopped = false
6+
flow.once()
7+
.await(() => promise)
8+
.cleanup(() => stopped = true)
9+
10+
flow.now();
11+
await 'microtask'
12+
flow.now();
13+
assert(!stopped);
14+
15+
resolve()
16+
await 'microtask'
17+
assert(stopped);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const { Flow } = self.yozo;
2+
const flow = new Flow();
3+
let first = 0
4+
let second = 0
5+
let stopped = false
6+
flow.await(() => 'microtask')
7+
.then(() => first++)
8+
.await(() => 'microtask')
9+
.then(() => second++)
10+
.once()
11+
.cleanup(() => stopped = true)
12+
13+
flow.now()
14+
await 'microtask'
15+
flow.now()
16+
17+
assert(first == 1)
18+
assert(second == 0)
19+
assert(!stopped)
20+
21+
await 'microtask'
22+
assert(first == 1)
23+
assert(second == 1)
24+
assert(stopped)

test/flow/once/return-value.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const { Flow } = self.yozo;
2+
const flow = new Flow();
3+
4+
assert(flow.once() == flow);
5+
6+
flow.stop();

0 commit comments

Comments
 (0)