-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbun.test.ts
59 lines (55 loc) · 1.23 KB
/
bun.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
54
55
56
57
58
59
import { expect, test } from "bun:test";
import withWith from "./src/index.ts";
test("lifter", () => {
const hello = 0;
let general = "kenobi";
withWith(
{ hello: () => "there" },
({ hello }) => {
expect(hello).toBeFunction();
// @ts-ignore Arguments must only be for satisfying types.
expect(hello()).toBe("there");
// @ts-ignore Arguments must only be for satisfying types.
expect(general).toBe("kenobi");
// @ts-ignore Arguments must only be for satisfying types.
general = "skywalker";
// @ts-ignore Arguments must only be for satisfying types.
expect(general).toBe("skywalker");
},
{ lifter: (data) => eval(data.eval) }
);
expect(hello).toBe(0);
});
test("return value", () => {
expect(
withWith(
{ value: () => 2 + 2 },
({ value }) => {
return value();
},
{ lifter: (data) => eval(data.eval) }
)
).toBe(4);
});
test("binding", () => {
expect(
withWith(
{},
function () {
return this;
},
{ binding: { exists: "yes" } }
)
).toEqual({ exists: "yes" });
});
test("array", () => {
expect(
withWith(
[1, 2, 3],
() => {
return toString();
},
{ binding: { exists: "yes" } }
)
).toBe("1,2,3");
});