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.
47 lines
1.1 KiB
47 lines
1.1 KiB
7 years ago
|
import test from 'ava';
|
||
6 years ago
|
import ow from '../source';
|
||
6 years ago
|
import {createAnyError} from './fixtures/create-error';
|
||
7 years ago
|
|
||
|
test('any', t => {
|
||
6 years ago
|
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(
|
||
7 years ago
|
'Expected argument to be of type `number` but received type `boolean`',
|
||
|
'Expected argument to be of type `string` but received type `boolean`'
|
||
|
));
|
||
|
});
|
||
6 years ago
|
|
||
|
test('any inception', t => {
|
||
6 years ago
|
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)));
|
||
|
});
|
||
6 years ago
|
});
|