-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TypioType.test.ts
58 lines (56 loc) · 1.46 KB
/
TypioType.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
import { CastResult } from "./typings";
import { TypioType } from "./TypioType";
describe("TypioType tests", () => {
it("when operator return false should return error withour operator error description", () => {
const operator = (() => false) as any;
operator.label = "oper1";
const typ = new TypioType(
[operator],
(): CastResult<any> => {
return {
type: "success",
value: "x",
};
},
);
const res = typ.cast("");
expect(res).toEqual({
type: "error",
operator: operator.label,
error: undefined,
value: "x",
});
});
it("when operator return true should return success with value", () => {
const operator = (() => true) as any;
operator.label = "oper1";
const typ = new TypioType([operator], () => {
return {
type: "success",
value: "x",
};
});
const res = typ.cast("");
expect(res).toEqual({
type: "success",
value: "x",
});
});
it("when operator return string should return string should return type error with operator error", () => {
const operator = (() => "error1") as any;
operator.label = "oper1";
const typ = new TypioType([operator], () => {
return {
type: "success",
value: "x",
};
});
const res = typ.cast("");
expect(res).toEqual({
type: "error",
operator: operator.label,
error: "error1",
value: "x",
});
});
});