Better tests

This commit is contained in:
Sebastian Seedorf
2020-05-27 13:02:19 +02:00
parent 9a46e52f93
commit 5fc32d7414
8 changed files with 34 additions and 30 deletions

View File

@@ -52,7 +52,7 @@ Deno.test("validate schema (match)", async () => {
], ],
]; ];
for (const [value, constraints] of values) { for (const [value, constraints] of values) {
assertEquals([], await validate(value, constraints)); assertEquals(await validate(value, constraints), [], String(value));
} }
}); });
@@ -92,6 +92,6 @@ Deno.test("validate schema (no match)", async () => {
], ],
]; ];
for (const [value, constraints] of values) { for (const [value, constraints] of values) {
assertNotEquals([], await validate(value, constraints)); assertNotEquals(await validate(value, constraints), [], String(value));
} }
}); });

View File

@@ -13,7 +13,7 @@ Deno.test("isArray (match)", async () => {
["foo"], ["foo"],
]; ];
for (const value of values) { for (const value of values) {
assertEquals(await validate(value, isArray()), []); assertEquals(await validate(value, isArray()), [], String(value));
} }
}); });
@@ -33,6 +33,6 @@ Deno.test("isArray (no match)", async () => {
Symbol(), Symbol(),
]; ];
for (const value of values) { for (const value of values) {
assertNotEquals(await validate(value, isArray()), []); assertNotEquals(await validate(value, isArray()), [], String(value));
} }
}); });

View File

@@ -13,7 +13,7 @@ Deno.test("isBoolean (match)", async () => {
false, false,
]; ];
for (const value of values) { for (const value of values) {
assertEquals(await validate(value, isBoolean()), []); assertEquals(await validate(value, isBoolean()), [], String(value));
} }
}); });
@@ -31,6 +31,6 @@ Deno.test("isBoolean (no match)", async () => {
Symbol(), Symbol(),
]; ];
for (const value of values) { for (const value of values) {
assertNotEquals(await validate(value, isBoolean()), []); assertNotEquals(await validate(value, isBoolean()), [], String(value));
} }
}); });

View File

@@ -80,7 +80,7 @@ Deno.test("isNotEmpty (match)", async () => {
Symbol("foo"), Symbol("foo"),
]; ];
for (const value of values) { for (const value of values) {
assertEquals(await validate(value, isNotEmpty()), []); assertEquals(await validate(value, isNotEmpty()), [], String(value));
} }
}); });
@@ -94,6 +94,6 @@ Deno.test("isNotEmpty (no match)", async () => {
[], [],
]; ];
for (const value of values) { for (const value of values) {
assertNotEquals(await validate(value, isNotEmpty()), []); assertNotEquals(await validate(value, isNotEmpty()), [], String(value));
} }
}); });

View File

@@ -11,7 +11,7 @@ Deno.test("or (match)", async () => {
[1, [isString(), isInteger()]], [1, [isString(), isInteger()]],
]; ];
for (const [value, validators] of values) { for (const [value, validators] of values) {
assertEquals(await validate(value, or(...validators)), []); assertEquals(await validate(value, or(...validators)), [], String(value));
} }
}); });
@@ -22,6 +22,10 @@ Deno.test("or (no match)", async () => {
[1, [isString()]], [1, [isString()]],
]; ];
for (const [value, validators] of values) { for (const [value, validators] of values) {
assertNotEquals(await validate(value, or(...validators)), []); assertNotEquals(
await validate(value, or(...validators)),
[],
String(value),
);
} }
}); });

View File

@@ -49,9 +49,13 @@ Deno.test("isInteger (match)", async () => {
-1, -1,
]; ];
for (const value of values) { for (const value of values) {
assertEquals(await validate(value, isInteger()), []); assertEquals(await validate(value, isInteger()), [], String(value));
} }
assertEquals(await validate(NaN, isInteger({ allowNaN: true })), []); assertEquals(
await validate(NaN, isInteger({ allowNaN: true })),
[],
String(NaN),
);
}); });
Deno.test("isInteger (no match)", async () => { Deno.test("isInteger (no match)", async () => {
@@ -67,7 +71,11 @@ Deno.test("isInteger (no match)", async () => {
0.1, 0.1,
]; ];
for (const value of values) { for (const value of values) {
assertNotEquals(await validate(value, isInteger()), []); assertNotEquals(await validate(value, isInteger()), [], String(value));
} }
assertNotEquals(await validate(NaN, isInteger({ allowNaN: false })), []); assertNotEquals(
await validate(NaN, isInteger({ allowNaN: false })),
[],
String(NaN),
);
}); });

View File

@@ -15,7 +15,7 @@ Deno.test("isString (match)", async () => {
new String("bar"), new String("bar"),
]; ];
for (const value of values) { for (const value of values) {
assertEquals(await validate(value, isString()), []); assertEquals(await validate(value, isString()), [], String(value));
} }
}); });
@@ -31,7 +31,7 @@ Deno.test("isString (no match)", async () => {
Symbol(), Symbol(),
]; ];
for (const value of values) { for (const value of values) {
assertNotEquals(await validate(value, isString()), []); assertNotEquals(await validate(value, isString()), [], String(value));
} }
}); });
@@ -47,7 +47,7 @@ Deno.test("isUrl (match)", async () => {
assertEquals( assertEquals(
await validate(value, isUrl({ allowLocal: true, allowDataUrl: true })), await validate(value, isUrl({ allowLocal: true, allowDataUrl: true })),
[], [],
"" + value, String(value),
); );
} }
}); });
@@ -66,7 +66,7 @@ Deno.test("isUrl (no match)", async () => {
assertNotEquals( assertNotEquals(
await validate(value, isUrl({ allowLocal: true })), await validate(value, isUrl({ allowLocal: true })),
[], [],
"" + value, String(value),
); );
} }
}); });
@@ -88,11 +88,7 @@ Deno.test("isEmail (match)", async () => {
"firstname-lastname@example.com", "firstname-lastname@example.com",
]; ];
for (const value of values) { for (const value of values) {
assertEquals( assertEquals(await validate(value, isEmail()), [], String(value));
await validate(value, isEmail()),
[],
"" + value,
);
} }
}); });
@@ -117,10 +113,6 @@ Deno.test("isEmail (no match)", async () => {
"Abc..123@example.com", "Abc..123@example.com",
]; ];
for (const value of values) { for (const value of values) {
assertNotEquals( assertNotEquals(await validate(value, isEmail()), [], String(value));
await validate(value, isEmail()),
[],
"" + value,
);
} }
}); });

View File

@@ -12,7 +12,7 @@ Deno.test("isSymbol (match)", async () => {
Symbol(), Symbol(),
]; ];
for (const value of values) { for (const value of values) {
assertEquals(await validate(value, isSymbol()), []); assertEquals(await validate(value, isSymbol()), [], String(value));
} }
}); });
@@ -31,6 +31,6 @@ Deno.test("isSymbol (no match)", async () => {
new Object(), new Object(),
]; ];
for (const value of values) { for (const value of values) {
assertNotEquals(await validate(value, isSymbol()), []); assertNotEquals(await validate(value, isSymbol()), [], String(value));
} }
}); });