You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// it("should value equals to other field", () => {
32
32
// // TODO: move from validator.spec.js
33
33
// });
34
+
35
+
describe("object strict test",function(){
36
+
it("should pass simple test",()=>{
37
+
constv=newValidator({
38
+
useNewCustomCheckerFunction: true,
39
+
});
40
+
constcheck=v.compile({
41
+
$$root: true,
42
+
type: "multi",
43
+
rules: ["string","number"]
44
+
});
45
+
expect(check(1)).toBe(true);
46
+
expect(check("1")).toBe(true);
47
+
expect(check({a: 1})).toEqual([{"actual": {"a": 1},"field": undefined,"message": "The '' field must be a string.","type": "string"},{"actual": {"a": 1},"field": undefined,"message": "The '' field must be a number.","type": "number"}]);
48
+
});
49
+
it("should pass object strict remove",()=>{
50
+
constv=newValidator({
51
+
useNewCustomCheckerFunction: true,
52
+
});
53
+
54
+
v.alias("targetA",{
55
+
type: "object",strict: "remove",props: {
56
+
a: "number"
57
+
}
58
+
});
59
+
60
+
v.alias("targetB",{
61
+
type: "object",strict: "remove",props: {
62
+
b: "number"
63
+
}
64
+
});
65
+
66
+
v.alias("targetC",{
67
+
type: "object",props: {
68
+
c: "number"
69
+
}
70
+
});
71
+
72
+
constcheck=v.compile({
73
+
$$root: true,
74
+
type: "multi",
75
+
rules: ["targetA","targetB","targetC"]
76
+
});
77
+
78
+
expect(check({a: 1})).toBe(true);
79
+
80
+
consttestB={b: 2,z: 3};
81
+
expect(check(testB)).toBe(true);
82
+
expect(testB).toEqual({b: 2});
83
+
84
+
consttestC={c: 3,d: 4};
85
+
expect(check(testC)).toBe(true);
86
+
expect(testC).toEqual({c: 3,d: 4});
87
+
88
+
expect(check({d: 4})).toEqual([{"actual": undefined,"field": "a","message": "The 'a' field is required.","type": "required"},{"actual": undefined,"field": "b","message": "The 'b' field is required.","type": "required"},{"actual": undefined,"field": "c","message": "The 'c' field is required.","type": "required"}]);
0 commit comments