/
test56.ts
74 lines (41 loc) 路 1.45 KB
/
test56.ts
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
import { Evt } from "../lib/index.ts";
import { EventEmitter } from "https://deno.land/std@0.85.0/node/events.ts";
import { getPromiseAssertionApi } from "../tools/testing/index.ts";
import { assert } from "https://raw.githubusercontent.com/garronej/tsafe/v1.0.0/deno_dist/assert.ts";
(async () => {
{
const { mustResolve } = getPromiseAssertionApi();
const ee = new EventEmitter();
const ctx = Evt.newCtx();
const evtText = Evt.from<string>(ctx, ee, "text");
const text = "ok";
for( const _ of [聽0, 1, 2 ] ) {
const pr = mustResolve({
"promise": evtText.waitFor(),
"expectedData": text
});
ee.emit("text", text);
await pr;
}
assert(ctx.getHandlers().length === 0 );
assert(ee.listenerCount("text") === 1);
ctx.done();
assert(ee.listenerCount("text") === 0);
}
{
const { mustResolve } = getPromiseAssertionApi();
const ee = new EventEmitter();
const evtText = Evt.from<string>(ee, "text");
const text = "ok";
for( const _ of [聽0, 1, 2 ] ) {
const pr = mustResolve({
"promise": evtText.waitFor(),
"expectedData": text
});
ee.emit("text", text);
await pr;
}
assert(ee.listenerCount("text") === 1);
}
console.log("PASS");
})();