mirror of https://github.com/lukechilds/ow.git
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.
46 lines
1.1 KiB
46 lines
1.1 KiB
import test from 'ava';
|
|
import ow from '../source';
|
|
import {createAnyError} from './fixtures/create-error';
|
|
|
|
test('any', t => {
|
|
t.notThrows(() => {
|
|
ow(1, ow.any(ow.number));
|
|
});
|
|
|
|
t.notThrows(() => {
|
|
ow(1, ow.any(ow.number, ow.string));
|
|
});
|
|
|
|
t.notThrows(() => {
|
|
ow(1, ow.any(ow.number, ow.string));
|
|
});
|
|
|
|
t.notThrows(() => {
|
|
ow(true, ow.any(ow.number, ow.string, ow.boolean));
|
|
});
|
|
|
|
t.throws(() => {
|
|
ow(1 as any, ow.any(ow.string));
|
|
}, createAnyError('Expected argument to be of type `string` but received type `number`'));
|
|
|
|
t.throws(() => {
|
|
ow(true as any, ow.any(ow.number, ow.string));
|
|
}, createAnyError(
|
|
'Expected argument to be of type `number` but received type `boolean`',
|
|
'Expected argument to be of type `string` but received type `boolean`'
|
|
));
|
|
});
|
|
|
|
test('any inception', t => {
|
|
t.notThrows(() => {
|
|
ow(1, ow.any(ow.number, ow.any(ow.string, ow.boolean)));
|
|
});
|
|
|
|
t.notThrows(() => {
|
|
ow('1', ow.any(ow.number, ow.any(ow.string, ow.boolean)));
|
|
});
|
|
|
|
t.notThrows(() => {
|
|
ow(true, ow.any(ow.number, ow.any(ow.string, ow.boolean)));
|
|
});
|
|
});
|
|
|