-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathbundle.test.ts
53 lines (46 loc) · 1.34 KB
/
bundle.test.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
import bundle, { bundleSync } from "./bundle.ts";
import { assertEquals, assertRejects, assertThrows } from "testing/asserts.ts";
import { assertSpyCallArgs, assertSpyCalls, spy } from "testing/mock.ts";
Deno.test("bundle", async () => {
const funA = spy((a: number, _b: string) => a);
const funB = spy((_a: number, b: string) => b);
assertEquals(await bundle(funA, funB)(1, "a"), undefined);
assertSpyCalls(funA, 1);
assertSpyCalls(funB, 1);
assertSpyCallArgs(funA, 0, [1, "a"]);
assertSpyCallArgs(funB, 0, [1, "a"]);
await assertRejects(() =>
bundle(
funA,
(_a, _b) => {
throw new Error();
},
funB,
)(0, "")
);
assertSpyCalls(funA, 2);
assertSpyCalls(funB, 2);
assertSpyCallArgs(funA, 1, [0, ""]);
assertSpyCallArgs(funB, 1, [0, ""]);
});
Deno.test("bundle sync", () => {
const funA = spy((a: number, _b: string) => a);
const funB = spy((_a: number, b: string) => b);
assertEquals(bundleSync(funA, funB)(1, "a"), undefined);
assertSpyCalls(funA, 1);
assertSpyCalls(funB, 1);
assertSpyCallArgs(funA, 0, [1, "a"]);
assertSpyCallArgs(funB, 0, [1, "a"]);
assertThrows(() =>
bundleSync(
funA,
(_a, _b) => {
throw new Error();
},
funB,
)(0, "")
);
assertSpyCalls(funA, 2);
assertSpyCalls(funB, 1);
assertSpyCallArgs(funA, 1, [0, ""]);
});