You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

29 lines
648 B

import test from 'ava';
import ow from '../source';
test('optional', t => {
t.notThrows(() => {
ow(1, ow.optional.number);
});
t.notThrows(() => {
ow(undefined, ow.optional.number);
});
t.notThrows(() => {
ow(undefined, ow.optional.string.minLength(3));
});
t.notThrows(() => {
ow(undefined, ow.optional.any(ow.string, ow.number));
});
t.throws(() => {
// tslint:disable-next-line
ow(null, ow.optional.number);
}, 'Expected argument to be of type `number` but received type `null`');
t.throws(() => {
ow('1' as any, ow.optional.number);
}, 'Expected argument to be of type `number` but received type `string`');
});