-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
48 lines (37 loc) · 1.11 KB
/
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
/* eslint-disable no-magic-numbers, no-undefined, flowtype/require-variable-type */
import { spy } from "sinon";
import forEach from "./index";
const unction = spy(([value, key]) => [value, key]);
const sample = (value) => (key) => unction([value, key]);
test("Array", () => {
forEach(sample)(["a", "b", "c"]);
expect(unction.calledWith(["a", 0])).toBeTruthy();
expect(unction.calledWith(["b", 1])).toBeTruthy();
expect(unction.calledWith(["c", 2])).toBeTruthy();
});
test("Object", () => {
forEach(sample)({
aaa: "1",
bbb: "2",
ccc: "3",
});
expect(unction.calledWith(["1", "aaa"])).toBeTruthy();
expect(unction.calledWith(["2", "bbb"])).toBeTruthy();
expect(unction.calledWith(["3", "ccc"])).toBeTruthy();
});
test("Map", () => {
forEach(sample)(new Map([
["a", "b"],
["c", "d"],
]));
expect(unction.calledWith(["b", "a"])).toBeTruthy();
expect(unction.calledWith(["d", "c"])).toBeTruthy();
});
test("Set", () => {
forEach(sample)(new Set([
"a",
"b",
]));
expect(unction.calledWith(["a", "a"])).toBeTruthy();
expect(unction.calledWith(["b", "b"])).toBeTruthy();
});