[IMP] validation: add support for value types

This commit add supports for value types in prop validation. To describe
a value V type, one has to simply write {value: V}.

Note that this commit also improves the validation typing.

closes #1198
closes #910
This commit is contained in:
Géry Debongnie
2022-06-14 18:05:58 +02:00
committed by Sam Degueldre
parent 55ac43c1db
commit 9c4c3e3b83
3 changed files with 38 additions and 4 deletions
+26
View File
@@ -248,4 +248,30 @@ describe("validateSchema", () => {
expect(validateSchema({ size: "sall" }, schema)).toEqual(["'size' is not valid"]);
expect(validateSchema({ size: 1 }, schema)).toEqual(["'size' is not a string"]);
});
test("value as type", () => {
expect(validateSchema({ a: false }, { a: { value: false } })).toEqual([]);
expect(validateSchema({ a: true }, { a: { value: false } })).toEqual([
"'a' is not equal to 'false'",
]);
});
test("value as type (some other values)", () => {
expect(validateSchema({ a: null }, { a: { value: null } })).toEqual([]);
expect(validateSchema({ a: false }, { a: { value: null } })).toEqual([
"'a' is not equal to 'null'",
]);
expect(validateSchema({ a: "hey" }, { a: { value: "hey" } })).toEqual([]);
expect(validateSchema({ a: true }, { a: { value: "hey" } })).toEqual([
"'a' is not equal to 'hey'",
]);
});
test("value as type work in union type", () => {
expect(validateSchema({ a: false }, { a: [String, { value: false }] })).toEqual([]);
expect(validateSchema({ a: true }, { a: [String, { value: false }] })).toEqual([
"'a' is not a string or false",
]);
expect(validateSchema({ a: "string" }, { a: [String, { value: false }] })).toEqual([]);
});
});