Skip to content

Commit c4a7bc1

Browse files
committed
test: check that empty arrays pass
While debugging an unrelated issue, I thought there may be a bug with empty arrays being rejected as valid input. Since there was no unit test covering this case, I was unable to rule this out. This wasted some debugging time following a red herring. So here is a unit test to cover this case so that in the future I only need to check the unit tests to this out as a potential source of bug.
1 parent 2c1056d commit c4a7bc1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/unit/array.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,15 @@ test('Can add JSON Schema options', () => {
4141
if (validator.isValid(x)) fail();
4242
else pass();
4343
});
44+
45+
test('Can validate empty array', () => {
46+
const x: any = [];
47+
48+
const validator = v.array(v.number());
49+
if (validator.isValid(x)) {
50+
assertTypesEqual<typeof x, number[]>();
51+
pass();
52+
} else {
53+
fail();
54+
}
55+
});

0 commit comments

Comments
 (0)