This commit is contained in:
Sebastian Seedorf
2020-05-28 01:45:30 +02:00
parent ff891cd303
commit adf8c400bc
3 changed files with 27 additions and 26 deletions

View File

@@ -102,39 +102,37 @@ Deno.test("validate schema (no match)", async () => {
}
});
Deno.test("validate doConversion (match)", async () => {
const values: [any, Validatable, any][] = [
[
1,
isNumber(),
1
1,
],
[
"2",
isNumber(),
2
2,
],
[
"03",
isNumber(),
3
3,
],
[
{ foo: 3, bar: { baz: "4", other: "val" } },
{ foo: isNumber(), bar: { baz: isNumber() } },
{ foo: 3, bar: { baz: 4 } }
{ foo: 3, bar: { baz: 4 } },
],
];
for (const [value, constraints, conv] of values) {
const valueBefore = JSON.stringify(value);
const converted: any = {};
assertEquals(await validate(value, constraints, {doConversion: true, converted}), [], String(value));
assertEquals(
await validate(value, constraints, { doConversion: true, converted }),
[],
String(value),
);
const valueAfter = JSON.stringify(value);
assertEquals(valueAfter, valueBefore);
assertEquals(converted.hasOwnProperty("output"), true);
@@ -156,10 +154,14 @@ Deno.test("validate doConversion (no match)", async () => {
for (const [value, constraints] of values) {
const valueBefore = JSON.stringify(value);
const converted: any = {};
assertNotEquals(await validate(value, constraints, {doConversion: true, converted}), [], String(value));
assertNotEquals(
await validate(value, constraints, { doConversion: true, converted }),
[],
String(value),
);
const valueAfter = JSON.stringify(value);
assertEquals(valueAfter, valueBefore);
assertEquals(converted.hasOwnProperty("output"), true);
assertEquals(converted?.output, value);
}
});
});