-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
59 lines (46 loc) · 1.11 KB
/
index.test.js
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
const attributesTest = () => {
const factories = require("./");
factories.define("foo", () => ({ key: "a" }));
factories.define("bar", () => ({ key: "b" }));
const result = factories.build("foo", {
key: "c",
otherKey: "d",
bar: factories.build("bar")
});
if (result.key !== "c") {
console.error("test failed");
process.exit(1);
}
if (result.otherKey !== "d") {
console.error("test failed");
process.exit(1);
}
if (result.bar.key !== "b") {
console.error("test failed");
process.exit(1);
}
};
const utilsTest = () => {
const factories = require("./");
factories.define("foo", ({ counter, uuid }) => ({
id: counter(),
uuid: uuid()
}));
const results = [factories.build("foo"), factories.build("foo")];
if (results[0].id !== 1) {
console.error("test failed");
process.exit(1);
}
if (results[1].id !== 2) {
console.error("test failed");
process.exit(1);
}
if (results[0].uuid.length !== 36) {
console.error("test failed");
process.exit(1);
}
};
attributesTest();
utilsTest();
console.log("test passed");
process.exit(0);