Skip to content

Commit c34d3ca

Browse files
committed
test: add list optional tests
1 parent 1d35f1d commit c34d3ca

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

test/validators.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,20 @@ describe('listof validator', () => {
208208
describe('list validator', () => {
209209
const Person = createSchema({
210210
friends: _.list([_.string(), _.number()]),
211+
otherList: _.list([_.string({ minLength: [4, 'lower-bound'] })], { optional: true }),
211212
});
213+
214+
test('handles optional property', () => {
215+
expect(Person.validate({ friends: ['John', 42] })).toBe(null);
216+
expect(Person.validate({ friends: ['John', 42], otherList: [] })).toStrictEqual({
217+
otherList: { 0: TYPEERR },
218+
});
219+
expect(Person.validate({ friends: ['John', 42], otherList: ['hel'] })).toStrictEqual({
220+
otherList: { 0: 'lower-bound' },
221+
});
222+
expect(Person.validate({ friends: ['John', 42], otherList: ['hell'] })).toStrictEqual(null);
223+
});
224+
212225
test('emits correct error messages', () => {
213226
expect(Person.validate({ friends: [] })).toStrictEqual({ friends: { 0: TYPEERR, 1: TYPEERR } });
214227
expect(Person.validate({ friends: {} })).toStrictEqual({ friends: TYPEERR });

0 commit comments

Comments
 (0)