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.
43 lines
1.3 KiB
43 lines
1.3 KiB
6 years ago
|
import test from 'ava';
|
||
|
import m from '..';
|
||
|
import {createAnyError} from './fixtures/create-error';
|
||
|
|
||
|
test('infer label', t => {
|
||
|
const foo = 'f';
|
||
|
|
||
|
t.throws(() => m(foo, m.string.minLength(2)), 'Expected string `foo` to have a minimum length of `2`, got `f`');
|
||
|
t.throws(() => m(foo as any, m.number), 'Expected `foo` to be of type `number` but received type `string`');
|
||
|
});
|
||
|
|
||
|
test('infer object property label', t => {
|
||
|
const hello = {
|
||
|
world: 'f'
|
||
|
};
|
||
|
|
||
|
t.throws(() => m(hello.world, m.string.minLength(2)), 'Expected string `hello.world` to have a minimum length of `2`, got `f`');
|
||
|
});
|
||
|
|
||
|
test('overwrite inferred label', t => {
|
||
|
const foo = 'f';
|
||
|
|
||
|
t.throws(() => m(foo, '🦄', m.string.minLength(2)), 'Expected string `🦄` to have a minimum length of `2`, got `f`');
|
||
|
});
|
||
|
|
||
|
test('infer label in `any` predicate', t => {
|
||
|
const foo = 'f';
|
||
|
|
||
|
t.throws(() => m(foo, m.any(m.string.minLength(2), m.number)), createAnyError(
|
||
|
'Expected string `foo` to have a minimum length of `2`, got `f`',
|
||
|
'Expected `foo` to be of type `number` but received type `string`'
|
||
|
));
|
||
|
});
|
||
|
|
||
|
test('overwrite inferred label in `any` predicate', t => {
|
||
|
const foo = 'f';
|
||
|
|
||
|
t.throws(() => m(foo, '🦄', m.any(m.string.minLength(2), m.number)), createAnyError(
|
||
|
'Expected string `🦄` to have a minimum length of `2`, got `f`',
|
||
|
'Expected `🦄` to be of type `number` but received type `string`'
|
||
|
));
|
||
|
});
|