From ece16e6da163dc22fd68828f805c8aecabf8c845 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 27 Jan 2019 03:21:33 +0700 Subject: [PATCH] Rename the variable used in tests from `m` to `ow` --- source/test/any.ts | 20 ++--- source/test/array-buffer.ts | 12 +-- source/test/array.ts | 72 +++++++-------- source/test/boolean.ts | 30 +++---- source/test/buffer.ts | 12 +-- source/test/data-view.ts | 10 +-- source/test/date.ts | 22 ++--- source/test/error.ts | 84 +++++++++--------- source/test/function.ts | 10 +-- source/test/infer-label.ts | 14 +-- source/test/iterable.ts | 12 +-- source/test/map.ts | 102 ++++++++++----------- source/test/nan.ts | 14 +-- source/test/null-or-undefined.ts | 14 +-- source/test/null.ts | 12 +-- source/test/number.ts | 148 +++++++++++++++---------------- source/test/object.ts | 96 ++++++++++---------- source/test/optional.ts | 12 +-- source/test/promise.ts | 12 +-- source/test/regexp.ts | 12 +-- source/test/set.ts | 78 ++++++++-------- source/test/string.ts | 138 ++++++++++++++-------------- source/test/symbol.ts | 10 +-- source/test/test.ts | 58 ++++++------ source/test/typed-array.ts | 70 +++++++-------- source/test/undefined.ts | 16 ++-- source/test/weak-map.ts | 28 +++--- source/test/weak-set.ts | 30 +++---- 28 files changed, 574 insertions(+), 574 deletions(-) diff --git a/source/test/any.ts b/source/test/any.ts index 2dc08e1..e3ac1d6 100644 --- a/source/test/any.ts +++ b/source/test/any.ts @@ -1,21 +1,21 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; import {createAnyError} from './fixtures/create-error'; test('any', t => { - t.notThrows(() => m(1, m.any(m.number))); - t.notThrows(() => m(1, m.any(m.number, m.string))); - t.notThrows(() => m(1, m.any(m.number, m.string))); - t.notThrows(() => m(true, m.any(m.number, m.string, m.boolean))); - t.throws(() => m(1 as any, m.any(m.string)), createAnyError('Expected argument to be of type `string` but received type `number`')); - t.throws(() => m(true as any, m.any(m.number, m.string)), createAnyError( + 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(() => m(1, m.any(m.number, m.any(m.string, m.boolean)))); - t.notThrows(() => m('1', m.any(m.number, m.any(m.string, m.boolean)))); - t.notThrows(() => m(true, m.any(m.number, m.any(m.string, m.boolean)))); + 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)))); }); diff --git a/source/test/array-buffer.ts b/source/test/array-buffer.ts index 2e87718..c44e619 100644 --- a/source/test/array-buffer.ts +++ b/source/test/array-buffer.ts @@ -1,10 +1,10 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('arrayBuffer', t => { - t.notThrows(() => m(new ArrayBuffer(1), m.arrayBuffer)); - t.notThrows(() => m(new ArrayBuffer(1), 'foo', m.arrayBuffer)); - t.throws(() => m('foo' as any, m.arrayBuffer), 'Expected argument to be of type `ArrayBuffer` but received type `string`'); - t.throws(() => m('foo' as any, 'foo', m.arrayBuffer), 'Expected `foo` to be of type `ArrayBuffer` but received type `string`'); - t.throws(() => m(12 as any, m.arrayBuffer), 'Expected argument to be of type `ArrayBuffer` but received type `number`'); + t.notThrows(() => ow(new ArrayBuffer(1), ow.arrayBuffer)); + t.notThrows(() => ow(new ArrayBuffer(1), 'foo', ow.arrayBuffer)); + t.throws(() => ow('foo' as any, ow.arrayBuffer), 'Expected argument to be of type `ArrayBuffer` but received type `string`'); + t.throws(() => ow('foo' as any, 'foo', ow.arrayBuffer), 'Expected `foo` to be of type `ArrayBuffer` but received type `string`'); + t.throws(() => ow(12 as any, ow.arrayBuffer), 'Expected argument to be of type `ArrayBuffer` but received type `number`'); }); diff --git a/source/test/array.ts b/source/test/array.ts index 5581edb..48142db 100644 --- a/source/test/array.ts +++ b/source/test/array.ts @@ -1,73 +1,73 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('array', t => { - t.notThrows(() => m([], m.array)); - t.notThrows(() => m([], 'foo', m.array)); - t.throws(() => m('12' as any, m.array), 'Expected argument to be of type `array` but received type `string`'); - t.throws(() => m('12' as any, 'foo', m.array), 'Expected `foo` to be of type `array` but received type `string`'); + t.notThrows(() => ow([], ow.array)); + t.notThrows(() => ow([], 'foo', ow.array)); + t.throws(() => ow('12' as any, ow.array), 'Expected argument to be of type `array` but received type `string`'); + t.throws(() => ow('12' as any, 'foo', ow.array), 'Expected `foo` to be of type `array` but received type `string`'); }); test('array.length', t => { - t.notThrows(() => m(['foo'], m.array.length(1))); - t.notThrows(() => m(['foo', 'bar'], m.array.length(2))); - t.throws(() => m(['foo'], m.array.length(2)), 'Expected array to have length `2`, got `1`'); - t.throws(() => m(['foo'], 'foo', m.array.length(2)), 'Expected array `foo` to have length `2`, got `1`'); + t.notThrows(() => ow(['foo'], ow.array.length(1))); + t.notThrows(() => ow(['foo', 'bar'], ow.array.length(2))); + t.throws(() => ow(['foo'], ow.array.length(2)), 'Expected array to have length `2`, got `1`'); + t.throws(() => ow(['foo'], 'foo', ow.array.length(2)), 'Expected array `foo` to have length `2`, got `1`'); }); test('array.minLength', t => { - t.notThrows(() => m(['foo'], m.array.minLength(1))); - t.notThrows(() => m(['foo', 'bar'], m.array.minLength(1))); - t.throws(() => m(['foo'], m.array.minLength(2)), 'Expected array to have a minimum length of `2`, got `1`'); + t.notThrows(() => ow(['foo'], ow.array.minLength(1))); + t.notThrows(() => ow(['foo', 'bar'], ow.array.minLength(1))); + t.throws(() => ow(['foo'], ow.array.minLength(2)), 'Expected array to have a minimum length of `2`, got `1`'); }); test('array.maxLength', t => { - t.notThrows(() => m(['foo'], m.array.maxLength(1))); - t.notThrows(() => m(['foo', 'bar'], m.array.maxLength(4))); - t.throws(() => m(['foo', 'bar'], m.array.maxLength(1)), 'Expected array to have a maximum length of `1`, got `2`'); + t.notThrows(() => ow(['foo'], ow.array.maxLength(1))); + t.notThrows(() => ow(['foo', 'bar'], ow.array.maxLength(4))); + t.throws(() => ow(['foo', 'bar'], ow.array.maxLength(1)), 'Expected array to have a maximum length of `1`, got `2`'); }); test('array.startsWith', t => { - t.notThrows(() => m(['foo', 'bar'], m.array.startsWith('foo'))); - t.throws(() => m(['foo', 'bar'], m.array.startsWith('bar')), 'Expected array to start with `bar`, got `foo`'); + t.notThrows(() => ow(['foo', 'bar'], ow.array.startsWith('foo'))); + t.throws(() => ow(['foo', 'bar'], ow.array.startsWith('bar')), 'Expected array to start with `bar`, got `foo`'); }); test('array.endsWith', t => { - t.notThrows(() => m(['foo', 'bar'], m.array.endsWith('bar'))); - t.throws(() => m(['foo', 'bar'], m.array.endsWith('foo')), 'Expected array to end with `foo`, got `bar`'); + t.notThrows(() => ow(['foo', 'bar'], ow.array.endsWith('bar'))); + t.throws(() => ow(['foo', 'bar'], ow.array.endsWith('foo')), 'Expected array to end with `foo`, got `bar`'); }); test('array.includes', t => { - t.notThrows(() => m(['foo', 'bar'], m.array.includes('foo'))); - t.notThrows(() => m(['foo', 'bar', 'unicorn'], m.array.includes('foo', 'bar'))); - t.throws(() => m(['foo', 'bar'], m.array.includes('foo', 'unicorn')), 'Expected array to include all elements of `["foo","unicorn"]`, got `["foo","bar"]`'); + t.notThrows(() => ow(['foo', 'bar'], ow.array.includes('foo'))); + t.notThrows(() => ow(['foo', 'bar', 'unicorn'], ow.array.includes('foo', 'bar'))); + t.throws(() => ow(['foo', 'bar'], ow.array.includes('foo', 'unicorn')), 'Expected array to include all elements of `["foo","unicorn"]`, got `["foo","bar"]`'); }); test('array.includesAny', t => { - t.notThrows(() => m(['foo', 'bar'], m.array.includesAny('foo'))); - t.notThrows(() => m(['foo', 'bar', 'unicorn'], m.array.includesAny('unicorn', 'rainbow'))); - t.throws(() => m(['foo', 'bar'], m.array.includesAny('unicorn')), 'Expected array to include any element of `["unicorn"]`, got `["foo","bar"]`'); + t.notThrows(() => ow(['foo', 'bar'], ow.array.includesAny('foo'))); + t.notThrows(() => ow(['foo', 'bar', 'unicorn'], ow.array.includesAny('unicorn', 'rainbow'))); + t.throws(() => ow(['foo', 'bar'], ow.array.includesAny('unicorn')), 'Expected array to include any element of `["unicorn"]`, got `["foo","bar"]`'); }); test('array.empty', t => { - t.notThrows(() => m([], m.array.empty)); - t.throws(() => m(['foo'], m.array.empty), 'Expected array to be empty, got `["foo"]`'); + t.notThrows(() => ow([], ow.array.empty)); + t.throws(() => ow(['foo'], ow.array.empty), 'Expected array to be empty, got `["foo"]`'); }); test('array.nonEmpty', t => { - t.notThrows(() => m(['foo'], m.array.nonEmpty)); - t.throws(() => m([], m.array.nonEmpty), 'Expected array to not be empty'); + t.notThrows(() => ow(['foo'], ow.array.nonEmpty)); + t.throws(() => ow([], ow.array.nonEmpty), 'Expected array to not be empty'); }); test('array.deepEqual', t => { - t.notThrows(() => m(['foo'], m.array.deepEqual(['foo']))); - t.notThrows(() => m(['foo', {id: 1}], m.array.deepEqual(['foo', {id: 1}]))); - t.throws(() => m(['foo', {id: 1}], m.array.deepEqual(['foo', {id: 2}])), 'Expected array to be deeply equal to `["foo",{"id":2}]`, got `["foo",{"id":1}]`'); + t.notThrows(() => ow(['foo'], ow.array.deepEqual(['foo']))); + t.notThrows(() => ow(['foo', {id: 1}], ow.array.deepEqual(['foo', {id: 1}]))); + t.throws(() => ow(['foo', {id: 1}], ow.array.deepEqual(['foo', {id: 2}])), 'Expected array to be deeply equal to `["foo",{"id":2}]`, got `["foo",{"id":1}]`'); }); test('array.ofType', t => { - t.notThrows(() => m(['foo', 'bar'], m.array.ofType(m.string))); - t.notThrows(() => m(['foo', 'bar'], m.array.ofType(m.string.minLength(3)))); - t.throws(() => m(['foo', 'b'], m.array.ofType(m.string.minLength(3))), '(array) Expected string to have a minimum length of `3`, got `b`'); - t.throws(() => m(['foo', 'b'], 'foo', m.array.ofType(m.string.minLength(3))), '(array `foo`) Expected string to have a minimum length of `3`, got `b`'); + t.notThrows(() => ow(['foo', 'bar'], ow.array.ofType(ow.string))); + t.notThrows(() => ow(['foo', 'bar'], ow.array.ofType(ow.string.minLength(3)))); + t.throws(() => ow(['foo', 'b'], ow.array.ofType(ow.string.minLength(3))), '(array) Expected string to have a minimum length of `3`, got `b`'); + t.throws(() => ow(['foo', 'b'], 'foo', ow.array.ofType(ow.string.minLength(3))), '(array `foo`) Expected string to have a minimum length of `3`, got `b`'); }); diff --git a/source/test/boolean.ts b/source/test/boolean.ts index 9d9a0f9..a5c080f 100644 --- a/source/test/boolean.ts +++ b/source/test/boolean.ts @@ -1,25 +1,25 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('boolean', t => { - t.notThrows(() => m(true, m.boolean)); - t.throws(() => m('12' as any, m.boolean), 'Expected argument to be of type `boolean` but received type `string`'); - t.throws(() => m('12' as any, 'foo', m.boolean), 'Expected `foo` to be of type `boolean` but received type `string`'); + t.notThrows(() => ow(true, ow.boolean)); + t.throws(() => ow('12' as any, ow.boolean), 'Expected argument to be of type `boolean` but received type `string`'); + t.throws(() => ow('12' as any, 'foo', ow.boolean), 'Expected `foo` to be of type `boolean` but received type `string`'); }); test('boolean.true', t => { - t.notThrows(() => m(true, m.boolean.true)); - t.notThrows(() => m(Boolean(true), m.boolean.true)); - t.notThrows(() => m(Boolean(1), m.boolean.true)); - t.throws(() => m(false, m.boolean.true), 'Expected boolean to be true, got false'); - t.throws(() => m(false, 'foo', m.boolean.true), 'Expected boolean `foo` to be true, got false'); - t.throws(() => m(Boolean(0), m.boolean.true), 'Expected boolean to be true, got false'); + t.notThrows(() => ow(true, ow.boolean.true)); + t.notThrows(() => ow(Boolean(true), ow.boolean.true)); + t.notThrows(() => ow(Boolean(1), ow.boolean.true)); + t.throws(() => ow(false, ow.boolean.true), 'Expected boolean to be true, got false'); + t.throws(() => ow(false, 'foo', ow.boolean.true), 'Expected boolean `foo` to be true, got false'); + t.throws(() => ow(Boolean(0), ow.boolean.true), 'Expected boolean to be true, got false'); }); test('boolean.false', t => { - t.notThrows(() => m(false, m.boolean.false)); - t.notThrows(() => m(Boolean(false), m.boolean.false)); - t.notThrows(() => m(Boolean(0), m.boolean.false)); - t.throws(() => m(true, m.boolean.false), 'Expected boolean to be false, got true'); - t.throws(() => m(Boolean(1), m.boolean.false), 'Expected boolean to be false, got true'); + t.notThrows(() => ow(false, ow.boolean.false)); + t.notThrows(() => ow(Boolean(false), ow.boolean.false)); + t.notThrows(() => ow(Boolean(0), ow.boolean.false)); + t.throws(() => ow(true, ow.boolean.false), 'Expected boolean to be false, got true'); + t.throws(() => ow(Boolean(1), ow.boolean.false), 'Expected boolean to be false, got true'); }); diff --git a/source/test/buffer.ts b/source/test/buffer.ts index 900d729..e501108 100644 --- a/source/test/buffer.ts +++ b/source/test/buffer.ts @@ -1,10 +1,10 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('buffer', t => { - t.notThrows(() => m(Buffer.alloc(2), m.buffer)); - t.notThrows(() => m(Buffer.from('f'), m.buffer)); - t.throws(() => m('foo' as any, m.buffer), 'Expected argument to be of type `Buffer` but received type `string`'); - t.throws(() => m('foo' as any, 'foo', m.buffer), 'Expected `foo` to be of type `Buffer` but received type `string`'); - t.throws(() => m(12 as any, m.buffer), 'Expected argument to be of type `Buffer` but received type `number`'); + t.notThrows(() => ow(Buffer.alloc(2), ow.buffer)); + t.notThrows(() => ow(Buffer.from('f'), ow.buffer)); + t.throws(() => ow('foo' as any, ow.buffer), 'Expected argument to be of type `Buffer` but received type `string`'); + t.throws(() => ow('foo' as any, 'foo', ow.buffer), 'Expected `foo` to be of type `Buffer` but received type `string`'); + t.throws(() => ow(12 as any, ow.buffer), 'Expected argument to be of type `Buffer` but received type `number`'); }); diff --git a/source/test/data-view.ts b/source/test/data-view.ts index 40724d1..1515c83 100644 --- a/source/test/data-view.ts +++ b/source/test/data-view.ts @@ -1,9 +1,9 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('dataView', t => { - t.notThrows(() => m(new DataView(new ArrayBuffer(1)), m.dataView)); - t.throws(() => m(new ArrayBuffer(1) as any, m.dataView), 'Expected argument to be of type `DataView` but received type `ArrayBuffer`'); - t.throws(() => m(new ArrayBuffer(1) as any, 'data', m.dataView), 'Expected `data` to be of type `DataView` but received type `ArrayBuffer`'); - t.throws(() => m(12 as any, m.dataView), 'Expected argument to be of type `DataView` but received type `number`'); + t.notThrows(() => ow(new DataView(new ArrayBuffer(1)), ow.dataView)); + t.throws(() => ow(new ArrayBuffer(1) as any, ow.dataView), 'Expected argument to be of type `DataView` but received type `ArrayBuffer`'); + t.throws(() => ow(new ArrayBuffer(1) as any, 'data', ow.dataView), 'Expected `data` to be of type `DataView` but received type `ArrayBuffer`'); + t.throws(() => ow(12 as any, ow.dataView), 'Expected argument to be of type `DataView` but received type `number`'); }); diff --git a/source/test/date.ts b/source/test/date.ts index 6f09928..4d282b7 100644 --- a/source/test/date.ts +++ b/source/test/date.ts @@ -1,21 +1,21 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('date', t => { - t.notThrows(() => m(new Date(), m.date)); - t.throws(() => m('12' as any, m.date), 'Expected argument to be of type `date` but received type `string`'); - t.throws(() => m('12' as any, 'foo', m.date), 'Expected `foo` to be of type `date` but received type `string`'); + t.notThrows(() => ow(new Date(), ow.date)); + t.throws(() => ow('12' as any, ow.date), 'Expected argument to be of type `date` but received type `string`'); + t.throws(() => ow('12' as any, 'foo', ow.date), 'Expected `foo` to be of type `date` but received type `string`'); }); test('date.before', t => { - t.notThrows(() => m(new Date('2017-11-25'), m.date.before(new Date('2017-11-26')))); - t.notThrows(() => m(new Date('2017-11-25T12:00:00Z'), m.date.before(new Date('2017-11-25T12:00:01Z')))); - t.throws(() => m(new Date('2017-11-25T12:00:00Z') as any, m.date.before(new Date('2017-11-25T12:00:00Z'))), 'Expected date 2017-11-25T12:00:00.000Z to be before 2017-11-25T12:00:00.000Z'); - t.throws(() => m(new Date('2017-11-25T12:00:00Z') as any, 'foo', m.date.before(new Date('2017-11-25T12:00:00Z'))), 'Expected date `foo` 2017-11-25T12:00:00.000Z to be before 2017-11-25T12:00:00.000Z'); + t.notThrows(() => ow(new Date('2017-11-25'), ow.date.before(new Date('2017-11-26')))); + t.notThrows(() => ow(new Date('2017-11-25T12:00:00Z'), ow.date.before(new Date('2017-11-25T12:00:01Z')))); + t.throws(() => ow(new Date('2017-11-25T12:00:00Z') as any, ow.date.before(new Date('2017-11-25T12:00:00Z'))), 'Expected date 2017-11-25T12:00:00.000Z to be before 2017-11-25T12:00:00.000Z'); + t.throws(() => ow(new Date('2017-11-25T12:00:00Z') as any, 'foo', ow.date.before(new Date('2017-11-25T12:00:00Z'))), 'Expected date `foo` 2017-11-25T12:00:00.000Z to be before 2017-11-25T12:00:00.000Z'); }); test('date.after', t => { - t.notThrows(() => m(new Date('2017-11-26'), m.date.after(new Date('2017-11-25')))); - t.notThrows(() => m(new Date('2017-11-26T12:00:00Z'), m.date.after(new Date('2017-11-26T11:59:59Z')))); - t.throws(() => m(new Date('2017-11-26T12:00:00Z') as any, m.date.after(new Date('2017-11-26T12:00:00Z'))), 'Expected date 2017-11-26T12:00:00.000Z to be after 2017-11-26T12:00:00.000Z'); + t.notThrows(() => ow(new Date('2017-11-26'), ow.date.after(new Date('2017-11-25')))); + t.notThrows(() => ow(new Date('2017-11-26T12:00:00Z'), ow.date.after(new Date('2017-11-26T11:59:59Z')))); + t.throws(() => ow(new Date('2017-11-26T12:00:00Z') as any, ow.date.after(new Date('2017-11-26T12:00:00Z'))), 'Expected date 2017-11-26T12:00:00.000Z to be after 2017-11-26T12:00:00.000Z'); }); diff --git a/source/test/error.ts b/source/test/error.ts index ae46176..f2e0db6 100644 --- a/source/test/error.ts +++ b/source/test/error.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; class CustomError extends Error { constructor(message: string) { @@ -9,30 +9,30 @@ class CustomError extends Error { } test('error', t => { - t.notThrows(() => m(new Error('foo'), m.error)); - t.throws(() => m('12' as any, m.error), 'Expected argument to be of type `error` but received type `string`'); - t.throws(() => m('12' as any, 'err', m.error), 'Expected `err` to be of type `error` but received type `string`'); + t.notThrows(() => ow(new Error('foo'), ow.error)); + t.throws(() => ow('12' as any, ow.error), 'Expected argument to be of type `error` but received type `string`'); + t.throws(() => ow('12' as any, 'err', ow.error), 'Expected `err` to be of type `error` but received type `string`'); }); test('error.name', t => { - t.notThrows(() => m(new Error('foo'), m.error.name('Error'))); - t.notThrows(() => m(new CustomError('foo'), m.error.name('CustomError'))); - t.notThrows(() => m(new CustomError('foo'), 'err', m.error.name('CustomError'))); - t.throws(() => m(new CustomError('foo'), m.error.name('Error')), 'Expected error to have name `Error`, got `CustomError`'); - t.throws(() => m(new CustomError('foo'), 'err', m.error.name('Error')), 'Expected error `err` to have name `Error`, got `CustomError`'); + t.notThrows(() => ow(new Error('foo'), ow.error.name('Error'))); + t.notThrows(() => ow(new CustomError('foo'), ow.error.name('CustomError'))); + t.notThrows(() => ow(new CustomError('foo'), 'err', ow.error.name('CustomError'))); + t.throws(() => ow(new CustomError('foo'), ow.error.name('Error')), 'Expected error to have name `Error`, got `CustomError`'); + t.throws(() => ow(new CustomError('foo'), 'err', ow.error.name('Error')), 'Expected error `err` to have name `Error`, got `CustomError`'); }); test('error.message', t => { - t.notThrows(() => m(new Error('foo'), m.error.message('foo'))); - t.notThrows(() => m(new CustomError('bar'), m.error.message('bar'))); - t.throws(() => m(new CustomError('foo'), m.error.message('bar')), 'Expected error message to be `bar`, got `foo`'); + t.notThrows(() => ow(new Error('foo'), ow.error.message('foo'))); + t.notThrows(() => ow(new CustomError('bar'), ow.error.message('bar'))); + t.throws(() => ow(new CustomError('foo'), ow.error.message('bar')), 'Expected error message to be `bar`, got `foo`'); }); test('error.messageIncludes', t => { - t.notThrows(() => m(new Error('foo bar'), m.error.messageIncludes('foo'))); - t.notThrows(() => m(new Error('foo bar'), m.error.messageIncludes('o'))); - t.notThrows(() => m(new CustomError('foo bar'), m.error.messageIncludes('bar'))); - t.throws(() => m(new CustomError('foo bar'), m.error.messageIncludes('unicorn')), 'Expected error message to include `unicorn`, got `foo bar`'); + t.notThrows(() => ow(new Error('foo bar'), ow.error.messageIncludes('foo'))); + t.notThrows(() => ow(new Error('foo bar'), ow.error.messageIncludes('o'))); + t.notThrows(() => ow(new CustomError('foo bar'), ow.error.messageIncludes('bar'))); + t.throws(() => ow(new CustomError('foo bar'), ow.error.messageIncludes('unicorn')), 'Expected error message to include `unicorn`, got `foo bar`'); }); test('error.hasKeys', t => { @@ -40,51 +40,51 @@ test('error.hasKeys', t => { err.unicorn = '🦄'; err.rainbow = '🌈'; - t.notThrows(() => m(err, m.error.hasKeys('unicorn'))); - t.notThrows(() => m(err, m.error.hasKeys('unicorn', 'rainbow'))); - t.throws(() => m(err, m.error.hasKeys('foo')), 'Expected error `err` message to have keys `foo`'); - t.throws(() => m(err, m.error.hasKeys('unicorn', 'foo')), 'Expected error `err` message to have keys `unicorn`, `foo`'); + t.notThrows(() => ow(err, ow.error.hasKeys('unicorn'))); + t.notThrows(() => ow(err, ow.error.hasKeys('unicorn', 'rainbow'))); + t.throws(() => ow(err, ow.error.hasKeys('foo')), 'Expected error `err` message to have keys `foo`'); + t.throws(() => ow(err, ow.error.hasKeys('unicorn', 'foo')), 'Expected error `err` message to have keys `unicorn`, `foo`'); }); test('error.instanceOf', t => { - t.notThrows(() => m(new CustomError('foo'), m.error.instanceOf(CustomError))); - t.notThrows(() => m(new CustomError('foo'), m.error.instanceOf(Error))); - t.notThrows(() => m(new TypeError('foo'), m.error.instanceOf(Error))); - t.notThrows(() => m(new Error('foo'), m.error.instanceOf(Error))); - t.notThrows(() => m(new Error('foo'), 'err', m.error.instanceOf(Error))); - t.throws(() => m(new Error('foo'), m.error.instanceOf(CustomError)), 'Expected error `Error` to be of type `CustomError`'); - t.throws(() => m(new Error('foo'), 'err', m.error.instanceOf(CustomError)), 'Expected error `err` `Error` to be of type `CustomError`'); - t.throws(() => m(new TypeError('foo'), m.error.instanceOf(EvalError)), 'Expected error `TypeError` to be of type `EvalError`'); - t.throws(() => m(new TypeError('foo'), 'err', m.error.instanceOf(EvalError)), 'Expected error `err` `TypeError` to be of type `EvalError`'); + t.notThrows(() => ow(new CustomError('foo'), ow.error.instanceOf(CustomError))); + t.notThrows(() => ow(new CustomError('foo'), ow.error.instanceOf(Error))); + t.notThrows(() => ow(new TypeError('foo'), ow.error.instanceOf(Error))); + t.notThrows(() => ow(new Error('foo'), ow.error.instanceOf(Error))); + t.notThrows(() => ow(new Error('foo'), 'err', ow.error.instanceOf(Error))); + t.throws(() => ow(new Error('foo'), ow.error.instanceOf(CustomError)), 'Expected error `Error` to be of type `CustomError`'); + t.throws(() => ow(new Error('foo'), 'err', ow.error.instanceOf(CustomError)), 'Expected error `err` `Error` to be of type `CustomError`'); + t.throws(() => ow(new TypeError('foo'), ow.error.instanceOf(EvalError)), 'Expected error `TypeError` to be of type `EvalError`'); + t.throws(() => ow(new TypeError('foo'), 'err', ow.error.instanceOf(EvalError)), 'Expected error `err` `TypeError` to be of type `EvalError`'); }); test('error.typeError', t => { - t.notThrows(() => m(new TypeError('foo'), m.error.typeError)); - t.throws(() => m(new Error('foo'), m.error.typeError), 'Expected error `Error` to be of type `TypeError`'); - t.throws(() => m(new Error('foo'), 'foo', m.error.typeError), 'Expected error `foo` `Error` to be of type `TypeError`'); + t.notThrows(() => ow(new TypeError('foo'), ow.error.typeError)); + t.throws(() => ow(new Error('foo'), ow.error.typeError), 'Expected error `Error` to be of type `TypeError`'); + t.throws(() => ow(new Error('foo'), 'foo', ow.error.typeError), 'Expected error `foo` `Error` to be of type `TypeError`'); }); test('error.evalError', t => { - t.notThrows(() => m(new EvalError('foo'), m.error.evalError)); - t.throws(() => m(new Error('foo'), m.error.evalError), 'Expected error `Error` to be of type `EvalError`'); + t.notThrows(() => ow(new EvalError('foo'), ow.error.evalError)); + t.throws(() => ow(new Error('foo'), ow.error.evalError), 'Expected error `Error` to be of type `EvalError`'); }); test('error.rangeError', t => { - t.notThrows(() => m(new RangeError('foo'), m.error.rangeError)); - t.throws(() => m(new EvalError('foo'), m.error.rangeError), 'Expected error `EvalError` to be of type `RangeError`'); + t.notThrows(() => ow(new RangeError('foo'), ow.error.rangeError)); + t.throws(() => ow(new EvalError('foo'), ow.error.rangeError), 'Expected error `EvalError` to be of type `RangeError`'); }); test('error.referenceError', t => { - t.notThrows(() => m(new ReferenceError('foo'), m.error.referenceError)); - t.throws(() => m(new Error('foo'), m.error.referenceError), 'Expected error `Error` to be of type `ReferenceError`'); + t.notThrows(() => ow(new ReferenceError('foo'), ow.error.referenceError)); + t.throws(() => ow(new Error('foo'), ow.error.referenceError), 'Expected error `Error` to be of type `ReferenceError`'); }); test('error.syntaxError', t => { - t.notThrows(() => m(new SyntaxError('foo'), m.error.syntaxError)); - t.throws(() => m(new Error('foo'), m.error.syntaxError), 'Expected error `Error` to be of type `SyntaxError`'); + t.notThrows(() => ow(new SyntaxError('foo'), ow.error.syntaxError)); + t.throws(() => ow(new Error('foo'), ow.error.syntaxError), 'Expected error `Error` to be of type `SyntaxError`'); }); test('error.uriError', t => { - t.notThrows(() => m(new URIError('foo'), m.error.uriError)); - t.throws(() => m(new Error('foo'), m.error.uriError), 'Expected error `Error` to be of type `URIError`'); + t.notThrows(() => ow(new URIError('foo'), ow.error.uriError)); + t.throws(() => ow(new Error('foo'), ow.error.uriError), 'Expected error `Error` to be of type `URIError`'); }); diff --git a/source/test/function.ts b/source/test/function.ts index 302341b..f6598bf 100644 --- a/source/test/function.ts +++ b/source/test/function.ts @@ -1,9 +1,9 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('function', t => { - t.notThrows(() => m(() => {}, m.function)); // tslint:disable-line:no-empty - t.throws(() => m('foo' as any, m.function), 'Expected argument to be of type `Function` but received type `string`'); - t.throws(() => m('foo' as any, 'foo', m.function), 'Expected `foo` to be of type `Function` but received type `string`'); - t.throws(() => m(12 as any, m.function), 'Expected argument to be of type `Function` but received type `number`'); + t.notThrows(() => ow(() => {}, ow.function)); // tslint:disable-line:no-empty + t.throws(() => ow('foo' as any, ow.function), 'Expected argument to be of type `Function` but received type `string`'); + t.throws(() => ow('foo' as any, 'foo', ow.function), 'Expected `foo` to be of type `Function` but received type `string`'); + t.throws(() => ow(12 as any, ow.function), 'Expected argument to be of type `Function` but received type `number`'); }); diff --git a/source/test/infer-label.ts b/source/test/infer-label.ts index 6075337..0cfa51c 100644 --- a/source/test/infer-label.ts +++ b/source/test/infer-label.ts @@ -1,12 +1,12 @@ import test from 'ava'; -import m from '..'; +import ow 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`'); + t.throws(() => ow(foo, ow.string.minLength(2)), 'Expected string `foo` to have a minimum length of `2`, got `f`'); + t.throws(() => ow(foo as any, ow.number), 'Expected `foo` to be of type `number` but received type `string`'); }); test('infer object property label', t => { @@ -14,19 +14,19 @@ test('infer object property label', t => { world: 'f' }; - t.throws(() => m(hello.world, m.string.minLength(2)), 'Expected string `hello.world` to have a minimum length of `2`, got `f`'); + t.throws(() => ow(hello.world, ow.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`'); + t.throws(() => ow(foo, '🦄', ow.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( + t.throws(() => ow(foo, ow.any(ow.string.minLength(2), ow.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`' )); @@ -35,7 +35,7 @@ test('infer label in `any` predicate', t => { test('overwrite inferred label in `any` predicate', t => { const foo = 'f'; - t.throws(() => m(foo, '🦄', m.any(m.string.minLength(2), m.number)), createAnyError( + t.throws(() => ow(foo, '🦄', ow.any(ow.string.minLength(2), ow.number)), createAnyError( 'Expected string `🦄` to have a minimum length of `2`, got `f`', 'Expected `🦄` to be of type `number` but received type `string`' )); diff --git a/source/test/iterable.ts b/source/test/iterable.ts index d020440..9b57d1f 100644 --- a/source/test/iterable.ts +++ b/source/test/iterable.ts @@ -1,10 +1,10 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('iterable', t => { - t.notThrows(() => m([], m.iterable)); - t.notThrows(() => m('foo', m.iterable)); - t.notThrows(() => m(new Map(), m.iterable)); - t.throws(() => m(12 as any, m.iterable), 'Expected argument to be of type `Iterable` but received type `number`'); - t.throws(() => m(12 as any, 'foo', m.iterable), 'Expected `foo` to be of type `Iterable` but received type `number`'); + t.notThrows(() => ow([], ow.iterable)); + t.notThrows(() => ow('foo', ow.iterable)); + t.notThrows(() => ow(new Map(), ow.iterable)); + t.throws(() => ow(12 as any, ow.iterable), 'Expected argument to be of type `Iterable` but received type `number`'); + t.throws(() => ow(12 as any, 'foo', ow.iterable), 'Expected `foo` to be of type `Iterable` but received type `number`'); }); diff --git a/source/test/map.ts b/source/test/map.ts index 4ef5069..b383407 100644 --- a/source/test/map.ts +++ b/source/test/map.ts @@ -1,91 +1,91 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('map', t => { - t.notThrows(() => m(new Map(), m.map)); - t.notThrows(() => m(new Map([['unicorn', '🦄']]), m.map)); - t.throws(() => m(12 as any, m.map), 'Expected argument to be of type `Map` but received type `number`'); - t.throws(() => m(12 as any, 'foo', m.map), 'Expected `foo` to be of type `Map` but received type `number`'); + t.notThrows(() => ow(new Map(), ow.map)); + t.notThrows(() => ow(new Map([['unicorn', '🦄']]), ow.map)); + t.throws(() => ow(12 as any, ow.map), 'Expected argument to be of type `Map` but received type `number`'); + t.throws(() => ow(12 as any, 'foo', ow.map), 'Expected `foo` to be of type `Map` but received type `number`'); }); test('map.size', t => { - t.notThrows(() => m(new Map(), m.map.size(0))); - t.notThrows(() => m(new Map([['unicorn', '🦄']]), m.map.size(1))); - t.throws(() => m(new Map([['unicorn', '🦄']]), m.map.size(0)), 'Expected Map to have size `0`, got `1`'); - t.throws(() => m(new Map([['unicorn', '🦄']]), 'foo', m.map.size(0)), 'Expected Map `foo` to have size `0`, got `1`'); + t.notThrows(() => ow(new Map(), ow.map.size(0))); + t.notThrows(() => ow(new Map([['unicorn', '🦄']]), ow.map.size(1))); + t.throws(() => ow(new Map([['unicorn', '🦄']]), ow.map.size(0)), 'Expected Map to have size `0`, got `1`'); + t.throws(() => ow(new Map([['unicorn', '🦄']]), 'foo', ow.map.size(0)), 'Expected Map `foo` to have size `0`, got `1`'); }); test('map.minSize', t => { - t.notThrows(() => m(new Map([['unicorn', '🦄']]), m.map.minSize(1))); - t.notThrows(() => m(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), m.map.minSize(1))); - t.throws(() => m(new Map([['unicorn', '🦄']]), m.map.minSize(2)), 'Expected Map to have a minimum size of `2`, got `1`'); + t.notThrows(() => ow(new Map([['unicorn', '🦄']]), ow.map.minSize(1))); + t.notThrows(() => ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.minSize(1))); + t.throws(() => ow(new Map([['unicorn', '🦄']]), ow.map.minSize(2)), 'Expected Map to have a minimum size of `2`, got `1`'); }); test('map.maxSize', t => { - t.notThrows(() => m(new Map([['unicorn', '🦄']]), m.map.maxSize(1))); - t.notThrows(() => m(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), m.map.maxSize(4))); - t.throws(() => m(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), m.map.maxSize(1)), 'Expected Map to have a maximum size of `1`, got `2`'); + t.notThrows(() => ow(new Map([['unicorn', '🦄']]), ow.map.maxSize(1))); + t.notThrows(() => ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.maxSize(4))); + t.throws(() => ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.maxSize(1)), 'Expected Map to have a maximum size of `1`, got `2`'); }); test('map.hasKeys', t => { - t.notThrows(() => m(new Map([['unicorn', '🦄']]), m.map.hasKeys('unicorn'))); - t.notThrows(() => m(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), m.map.hasKeys('unicorn', 'rainbow'))); - t.notThrows(() => m(new Map([[1, '🦄'], [2, '🌈']]), m.map.hasKeys(1, 2))); - t.throws(() => m(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), m.map.hasKeys('foo')), 'Expected Map to have keys `["foo"]`'); - t.throws(() => m(new Map([['unicorn', '🦄'], ['foo', '🌈']]), m.map.hasKeys('foo', 'bar')), 'Expected Map to have keys `["bar"]`'); - t.throws(() => m(new Map([[2, '🦄'], [4, '🌈']]), m.map.hasKeys(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)), 'Expected Map to have keys `[1,3,5,6,7]`'); + t.notThrows(() => ow(new Map([['unicorn', '🦄']]), ow.map.hasKeys('unicorn'))); + t.notThrows(() => ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.hasKeys('unicorn', 'rainbow'))); + t.notThrows(() => ow(new Map([[1, '🦄'], [2, '🌈']]), ow.map.hasKeys(1, 2))); + t.throws(() => ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.hasKeys('foo')), 'Expected Map to have keys `["foo"]`'); + t.throws(() => ow(new Map([['unicorn', '🦄'], ['foo', '🌈']]), ow.map.hasKeys('foo', 'bar')), 'Expected Map to have keys `["bar"]`'); + t.throws(() => ow(new Map([[2, '🦄'], [4, '🌈']]), ow.map.hasKeys(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)), 'Expected Map to have keys `[1,3,5,6,7]`'); }); test('map.hasAnyKeys', t => { - t.notThrows(() => m(new Map([['unicorn', '🦄']]), m.map.hasAnyKeys('unicorn', 'rainbow'))); - t.notThrows(() => m(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), m.map.hasAnyKeys('unicorn'))); - t.notThrows(() => m(new Map([[1, '🦄'], [2, '🌈']]), m.map.hasAnyKeys(1, 2, 3, 4))); - t.throws(() => m(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), m.map.hasAnyKeys('foo')), 'Expected Map to have any key of `["foo"]`'); + t.notThrows(() => ow(new Map([['unicorn', '🦄']]), ow.map.hasAnyKeys('unicorn', 'rainbow'))); + t.notThrows(() => ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.hasAnyKeys('unicorn'))); + t.notThrows(() => ow(new Map([[1, '🦄'], [2, '🌈']]), ow.map.hasAnyKeys(1, 2, 3, 4))); + t.throws(() => ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.hasAnyKeys('foo')), 'Expected Map to have any key of `["foo"]`'); }); test('map.hasValues', t => { - t.notThrows(() => m(new Map([['unicorn', '🦄']]), m.map.hasValues('🦄'))); - t.notThrows(() => m(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), m.map.hasValues('🦄', '🌈'))); - t.throws(() => m(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), m.map.hasValues('🦄', '🌦️')), 'Expected Map to have values `["🌦️"]`'); - t.throws(() => m(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), m.map.hasValues('🌈', '⚡', '👓', '🐬', '🎃', '🎶', '❤', '️🐳', '🍀', '👽')), 'Expected Map to have values `["⚡","👓","🐬","🎃","🎶"]`'); + t.notThrows(() => ow(new Map([['unicorn', '🦄']]), ow.map.hasValues('🦄'))); + t.notThrows(() => ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.hasValues('🦄', '🌈'))); + t.throws(() => ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.hasValues('🦄', '🌦️')), 'Expected Map to have values `["🌦️"]`'); + t.throws(() => ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.hasValues('🌈', '⚡', '👓', '🐬', '🎃', '🎶', '❤', '️🐳', '🍀', '👽')), 'Expected Map to have values `["⚡","👓","🐬","🎃","🎶"]`'); }); test('map.hasAnyValues', t => { - t.notThrows(() => m(new Map([['unicorn', '🦄']]), m.map.hasAnyValues('🦄', '🌈'))); - t.notThrows(() => m(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), m.map.hasAnyValues('🦄'))); - t.throws(() => m(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), m.map.hasAnyValues('🌦️')), 'Expected Map to have any value of `["🌦️"]`'); + t.notThrows(() => ow(new Map([['unicorn', '🦄']]), ow.map.hasAnyValues('🦄', '🌈'))); + t.notThrows(() => ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.hasAnyValues('🦄'))); + t.throws(() => ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.hasAnyValues('🌦️')), 'Expected Map to have any value of `["🌦️"]`'); }); test('map.keysOfType', t => { - t.notThrows(() => m(new Map([['unicorn', '🦄']]), m.map.keysOfType(m.string))); - t.notThrows(() => m(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), m.map.keysOfType(m.string.minLength(3)))); - t.notThrows(() => m(new Map([[1, '🦄']]), m.map.keysOfType(m.number))); - t.throws(() => m(new Map([['unicorn', '🦄']]), m.map.keysOfType(m.number)), '(Map) Expected argument to be of type `number` but received type `string`'); - t.throws(() => m(new Map([['unicorn', '🦄']]), 'foo', m.map.keysOfType(m.number)), '(Map `foo`) Expected argument to be of type `number` but received type `string`'); + t.notThrows(() => ow(new Map([['unicorn', '🦄']]), ow.map.keysOfType(ow.string))); + t.notThrows(() => ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.keysOfType(ow.string.minLength(3)))); + t.notThrows(() => ow(new Map([[1, '🦄']]), ow.map.keysOfType(ow.number))); + t.throws(() => ow(new Map([['unicorn', '🦄']]), ow.map.keysOfType(ow.number)), '(Map) Expected argument to be of type `number` but received type `string`'); + t.throws(() => ow(new Map([['unicorn', '🦄']]), 'foo', ow.map.keysOfType(ow.number)), '(Map `foo`) Expected argument to be of type `number` but received type `string`'); }); test('map.valuesOfType', t => { - t.notThrows(() => m(new Map([['unicorn', 1]]), m.map.valuesOfType(m.number))); - t.notThrows(() => m(new Map([['unicorn', 10], ['rainbow', 11]]), m.map.valuesOfType(m.number.greaterThanOrEqual(10)))); - t.notThrows(() => m(new Map([['unicorn', '🦄']]), m.map.valuesOfType(m.string))); - t.throws(() => m(new Map([['unicorn', '🦄']]), m.map.valuesOfType(m.number)), '(Map) Expected argument to be of type `number` but received type `string`'); - t.throws(() => m(new Map([['unicorn', '🦄']]), 'foo', m.map.valuesOfType(m.number)), '(Map `foo`) Expected argument to be of type `number` but received type `string`'); + t.notThrows(() => ow(new Map([['unicorn', 1]]), ow.map.valuesOfType(ow.number))); + t.notThrows(() => ow(new Map([['unicorn', 10], ['rainbow', 11]]), ow.map.valuesOfType(ow.number.greaterThanOrEqual(10)))); + t.notThrows(() => ow(new Map([['unicorn', '🦄']]), ow.map.valuesOfType(ow.string))); + t.throws(() => ow(new Map([['unicorn', '🦄']]), ow.map.valuesOfType(ow.number)), '(Map) Expected argument to be of type `number` but received type `string`'); + t.throws(() => ow(new Map([['unicorn', '🦄']]), 'foo', ow.map.valuesOfType(ow.number)), '(Map `foo`) Expected argument to be of type `number` but received type `string`'); }); test('map.empty', t => { - t.notThrows(() => m(new Map(), m.map.empty)); - t.notThrows(() => m(new Map([]), m.map.empty)); - t.throws(() => m(new Map([['unicorn', '🦄']]), m.map.empty), 'Expected Map to be empty, got `[["unicorn","🦄"]]`'); + t.notThrows(() => ow(new Map(), ow.map.empty)); + t.notThrows(() => ow(new Map([]), ow.map.empty)); + t.throws(() => ow(new Map([['unicorn', '🦄']]), ow.map.empty), 'Expected Map to be empty, got `[["unicorn","🦄"]]`'); }); test('map.notEmpty', t => { - t.notThrows(() => m(new Map([['unicorn', '🦄']]), m.map.nonEmpty)); - t.throws(() => m(new Map(), m.map.nonEmpty), 'Expected Map to not be empty'); + t.notThrows(() => ow(new Map([['unicorn', '🦄']]), ow.map.nonEmpty)); + t.throws(() => ow(new Map(), ow.map.nonEmpty), 'Expected Map to not be empty'); }); test('map.deepEqual', t => { - t.notThrows(() => m(new Map([['unicorn', '🦄']]), m.map.deepEqual(new Map([['unicorn', '🦄']])))); - t.notThrows(() => m(new Map([['foo', {foo: 'bar'}]]), m.map.deepEqual(new Map([['foo', {foo: 'bar'}]])))); - t.throws(() => m(new Map([['unicorn', '🦄']]), m.map.deepEqual(new Map([['rainbow', '🌈']]))), 'Expected Map to be deeply equal to `[["rainbow","🌈"]]`, got `[["unicorn","🦄"]]`'); - t.throws(() => m(new Map([['foo', {foo: 'bar'}]]), m.map.deepEqual(new Map([['foo', {foo: 'baz'}]]))), 'Expected Map to be deeply equal to `[["foo",{"foo":"baz"}]]`, got `[["foo",{"foo":"bar"}]]`'); + t.notThrows(() => ow(new Map([['unicorn', '🦄']]), ow.map.deepEqual(new Map([['unicorn', '🦄']])))); + t.notThrows(() => ow(new Map([['foo', {foo: 'bar'}]]), ow.map.deepEqual(new Map([['foo', {foo: 'bar'}]])))); + t.throws(() => ow(new Map([['unicorn', '🦄']]), ow.map.deepEqual(new Map([['rainbow', '🌈']]))), 'Expected Map to be deeply equal to `[["rainbow","🌈"]]`, got `[["unicorn","🦄"]]`'); + t.throws(() => ow(new Map([['foo', {foo: 'bar'}]]), ow.map.deepEqual(new Map([['foo', {foo: 'baz'}]]))), 'Expected Map to be deeply equal to `[["foo",{"foo":"baz"}]]`, got `[["foo",{"foo":"bar"}]]`'); }); diff --git a/source/test/nan.ts b/source/test/nan.ts index fc345bf..c8e99bf 100644 --- a/source/test/nan.ts +++ b/source/test/nan.ts @@ -1,11 +1,11 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('nan', t => { - t.notThrows(() => m(NaN, m.nan)); - t.notThrows(() => m(Number.NaN, m.nan)); - t.notThrows(() => m(0 / 0, m.nan)); - t.throws(() => m(12, m.nan), 'Expected argument to be of type `nan` but received type `number`'); - t.throws(() => m(12, 'foo', m.nan), 'Expected `foo` to be of type `nan` but received type `number`'); - t.throws(() => m('12' as any, m.nan), 'Expected argument to be of type `nan` but received type `string`'); + t.notThrows(() => ow(NaN, ow.nan)); + t.notThrows(() => ow(Number.NaN, ow.nan)); + t.notThrows(() => ow(0 / 0, ow.nan)); + t.throws(() => ow(12, ow.nan), 'Expected argument to be of type `nan` but received type `number`'); + t.throws(() => ow(12, 'foo', ow.nan), 'Expected `foo` to be of type `nan` but received type `number`'); + t.throws(() => ow('12' as any, ow.nan), 'Expected argument to be of type `nan` but received type `string`'); }); diff --git a/source/test/null-or-undefined.ts b/source/test/null-or-undefined.ts index 236aa25..baa2e24 100644 --- a/source/test/null-or-undefined.ts +++ b/source/test/null-or-undefined.ts @@ -1,14 +1,14 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('nullOrUndefined', t => { const x = null; const y = undefined; - t.notThrows(() => m(null, m.nullOrUndefined)); - t.notThrows(() => m(undefined, m.nullOrUndefined)); - t.notThrows(() => m(x, m.nullOrUndefined)); - t.notThrows(() => m(y, m.nullOrUndefined)); - t.throws(() => m('foo' as any, m.nullOrUndefined), 'Expected argument to be of type `nullOrUndefined` but received type `string`'); - t.throws(() => m('foo' as any, 'foo', m.nullOrUndefined), 'Expected `foo` to be of type `nullOrUndefined` but received type `string`'); + t.notThrows(() => ow(null, ow.nullOrUndefined)); + t.notThrows(() => ow(undefined, ow.nullOrUndefined)); + t.notThrows(() => ow(x, ow.nullOrUndefined)); + t.notThrows(() => ow(y, ow.nullOrUndefined)); + t.throws(() => ow('foo' as any, ow.nullOrUndefined), 'Expected argument to be of type `nullOrUndefined` but received type `string`'); + t.throws(() => ow('foo' as any, 'foo', ow.nullOrUndefined), 'Expected `foo` to be of type `nullOrUndefined` but received type `string`'); }); diff --git a/source/test/null.ts b/source/test/null.ts index b0b3f3c..3dec91b 100644 --- a/source/test/null.ts +++ b/source/test/null.ts @@ -1,12 +1,12 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('null', t => { const x = null; - t.notThrows(() => m(null, m.null)); - t.notThrows(() => m(x, m.null)); - t.throws(() => m(undefined as any, m.null), 'Expected argument to be of type `null` but received type `undefined`'); - t.throws(() => m(undefined as any, 'foo', m.null), 'Expected `foo` to be of type `null` but received type `undefined`'); - t.throws(() => m('foo' as any, m.null), 'Expected argument to be of type `null` but received type `string`'); + t.notThrows(() => ow(null, ow.null)); + t.notThrows(() => ow(x, ow.null)); + t.throws(() => ow(undefined as any, ow.null), 'Expected argument to be of type `null` but received type `undefined`'); + t.throws(() => ow(undefined as any, 'foo', ow.null), 'Expected `foo` to be of type `null` but received type `undefined`'); + t.throws(() => ow('foo' as any, ow.null), 'Expected argument to be of type `null` but received type `string`'); }); diff --git a/source/test/number.ts b/source/test/number.ts index c404e3d..a6789aa 100644 --- a/source/test/number.ts +++ b/source/test/number.ts @@ -1,132 +1,132 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('number', t => { - t.notThrows(() => m(1, m.number)); - t.throws(() => m('12' as any, m.number), 'Expected argument to be of type `number` but received type `string`'); - t.throws(() => m('12' as any, 'foo', m.number), 'Expected `foo` to be of type `number` but received type `string`'); + t.notThrows(() => ow(1, ow.number)); + t.throws(() => ow('12' as any, ow.number), 'Expected argument to be of type `number` but received type `string`'); + t.throws(() => ow('12' as any, 'foo', ow.number), 'Expected `foo` to be of type `number` but received type `string`'); }); test('number.inRange', t => { - t.notThrows(() => m(10, m.number.inRange(0, 20))); - t.notThrows(() => m(10, m.number.inRange(10, 20))); - t.notThrows(() => m(10, m.number.inRange(0, 10))); - t.throws(() => m(10 as any, m.number.inRange(0, 9)), 'Expected number to be in range [0..9], got 10'); - t.throws(() => m(10 as any, 'foo', m.number.inRange(0, 9)), 'Expected number `foo` to be in range [0..9], got 10'); - t.throws(() => m(10 as any, m.number.inRange(11, 20)), 'Expected number to be in range [11..20], got 10'); + t.notThrows(() => ow(10, ow.number.inRange(0, 20))); + t.notThrows(() => ow(10, ow.number.inRange(10, 20))); + t.notThrows(() => ow(10, ow.number.inRange(0, 10))); + t.throws(() => ow(10 as any, ow.number.inRange(0, 9)), 'Expected number to be in range [0..9], got 10'); + t.throws(() => ow(10 as any, 'foo', ow.number.inRange(0, 9)), 'Expected number `foo` to be in range [0..9], got 10'); + t.throws(() => ow(10 as any, ow.number.inRange(11, 20)), 'Expected number to be in range [11..20], got 10'); }); test('number.greaterThan', t => { - t.notThrows(() => m(10, m.number.greaterThan(5))); - t.notThrows(() => m(10, m.number.greaterThan(9))); - t.throws(() => m(10 as any, m.number.greaterThan(10)), 'Expected number to be greater than 10, got 10'); - t.throws(() => m(10 as any, m.number.greaterThan(11)), 'Expected number to be greater than 11, got 10'); - t.throws(() => m(10 as any, m.number.greaterThan(20)), 'Expected number to be greater than 20, got 10'); + t.notThrows(() => ow(10, ow.number.greaterThan(5))); + t.notThrows(() => ow(10, ow.number.greaterThan(9))); + t.throws(() => ow(10 as any, ow.number.greaterThan(10)), 'Expected number to be greater than 10, got 10'); + t.throws(() => ow(10 as any, ow.number.greaterThan(11)), 'Expected number to be greater than 11, got 10'); + t.throws(() => ow(10 as any, ow.number.greaterThan(20)), 'Expected number to be greater than 20, got 10'); }); test('number.greaterThanOrEqual', t => { - t.notThrows(() => m(10, m.number.greaterThanOrEqual(5))); - t.notThrows(() => m(10, m.number.greaterThanOrEqual(10))); - t.throws(() => m(10 as any, m.number.greaterThanOrEqual(11)), 'Expected number to be greater than or equal to 11, got 10'); - t.throws(() => m(10 as any, m.number.greaterThanOrEqual(20)), 'Expected number to be greater than or equal to 20, got 10'); + t.notThrows(() => ow(10, ow.number.greaterThanOrEqual(5))); + t.notThrows(() => ow(10, ow.number.greaterThanOrEqual(10))); + t.throws(() => ow(10 as any, ow.number.greaterThanOrEqual(11)), 'Expected number to be greater than or equal to 11, got 10'); + t.throws(() => ow(10 as any, ow.number.greaterThanOrEqual(20)), 'Expected number to be greater than or equal to 20, got 10'); }); test('number.lessThan', t => { - t.notThrows(() => m(10, m.number.lessThan(20))); - t.notThrows(() => m(10, m.number.lessThan(11))); - t.throws(() => m(10 as any, m.number.lessThan(10)), 'Expected number to be less than 10, got 10'); - t.throws(() => m(10 as any, m.number.lessThan(9)), 'Expected number to be less than 9, got 10'); - t.throws(() => m(10 as any, m.number.lessThan(0)), 'Expected number to be less than 0, got 10'); + t.notThrows(() => ow(10, ow.number.lessThan(20))); + t.notThrows(() => ow(10, ow.number.lessThan(11))); + t.throws(() => ow(10 as any, ow.number.lessThan(10)), 'Expected number to be less than 10, got 10'); + t.throws(() => ow(10 as any, ow.number.lessThan(9)), 'Expected number to be less than 9, got 10'); + t.throws(() => ow(10 as any, ow.number.lessThan(0)), 'Expected number to be less than 0, got 10'); }); test('number.lessThanOrEqual', t => { - t.notThrows(() => m(10, m.number.lessThanOrEqual(20))); - t.notThrows(() => m(10, m.number.lessThanOrEqual(10))); - t.throws(() => m(10 as any, m.number.lessThanOrEqual(9)), 'Expected number to be less than or equal to 9, got 10'); - t.throws(() => m(10 as any, m.number.lessThanOrEqual(0)), 'Expected number to be less than or equal to 0, got 10'); + t.notThrows(() => ow(10, ow.number.lessThanOrEqual(20))); + t.notThrows(() => ow(10, ow.number.lessThanOrEqual(10))); + t.throws(() => ow(10 as any, ow.number.lessThanOrEqual(9)), 'Expected number to be less than or equal to 9, got 10'); + t.throws(() => ow(10 as any, ow.number.lessThanOrEqual(0)), 'Expected number to be less than or equal to 0, got 10'); }); test('number.equal', t => { - t.notThrows(() => m(10, m.number.equal(10))); - t.throws(() => m(10 as any, m.number.equal(5)), 'Expected number to be equal to 5, got 10'); + t.notThrows(() => ow(10, ow.number.equal(10))); + t.throws(() => ow(10 as any, ow.number.equal(5)), 'Expected number to be equal to 5, got 10'); }); test('number.integer', t => { - t.notThrows(() => m(10, m.number.integer)); - t.throws(() => m(10.1 as any, m.number.integer), 'Expected number to be an integer, got 10.1'); + t.notThrows(() => ow(10, ow.number.integer)); + t.throws(() => ow(10.1 as any, ow.number.integer), 'Expected number to be an integer, got 10.1'); }); test('number.finite', t => { - t.notThrows(() => m(10, m.number.finite)); - t.throws(() => m(Infinity as any, m.number.finite), 'Expected number to be finite, got Infinity'); + t.notThrows(() => ow(10, ow.number.finite)); + t.throws(() => ow(Infinity as any, ow.number.finite), 'Expected number to be finite, got Infinity'); }); test('number.infinite', t => { - t.notThrows(() => m(Infinity, m.number.infinite)); - t.throws(() => m(10 as any, m.number.infinite), 'Expected number to be infinite, got 10'); + t.notThrows(() => ow(Infinity, ow.number.infinite)); + t.throws(() => ow(10 as any, ow.number.infinite), 'Expected number to be infinite, got 10'); }); test('number.positive', t => { - t.notThrows(() => m(1, m.number.positive)); - t.throws(() => m(-1 as any, m.number.positive), 'Expected number to be positive, got -1'); + t.notThrows(() => ow(1, ow.number.positive)); + t.throws(() => ow(-1 as any, ow.number.positive), 'Expected number to be positive, got -1'); }); test('number.negative', t => { - t.notThrows(() => m(-1, m.number.negative)); - t.throws(() => m(1 as any, m.number.negative), 'Expected number to be negative, got 1'); + t.notThrows(() => ow(-1, ow.number.negative)); + t.throws(() => ow(1 as any, ow.number.negative), 'Expected number to be negative, got 1'); }); test('number.integerOrInfinite', t => { - t.notThrows(() => m(10, m.number.integerOrInfinite)); - t.notThrows(() => m(Infinity, m.number.integerOrInfinite)); - t.notThrows(() => m(-10, m.number.integerOrInfinite)); - t.throws(() => m(3.14, m.number.integerOrInfinite), 'Expected number to be an integer or infinite, got 3.14'); + t.notThrows(() => ow(10, ow.number.integerOrInfinite)); + t.notThrows(() => ow(Infinity, ow.number.integerOrInfinite)); + t.notThrows(() => ow(-10, ow.number.integerOrInfinite)); + t.throws(() => ow(3.14, ow.number.integerOrInfinite), 'Expected number to be an integer or infinite, got 3.14'); }); test('number.uint8', t => { - t.notThrows(() => m(0, m.number.uint8)); - t.notThrows(() => m(255, m.number.uint8)); - t.throws(() => m(-1, m.number.uint8), 'Expected number to be in range [0..255], got -1'); - t.throws(() => m(1.5, m.number.uint8), 'Expected number to be an integer, got 1.5'); - t.throws(() => m(256, m.number.uint8), 'Expected number to be in range [0..255], got 256'); + t.notThrows(() => ow(0, ow.number.uint8)); + t.notThrows(() => ow(255, ow.number.uint8)); + t.throws(() => ow(-1, ow.number.uint8), 'Expected number to be in range [0..255], got -1'); + t.throws(() => ow(1.5, ow.number.uint8), 'Expected number to be an integer, got 1.5'); + t.throws(() => ow(256, ow.number.uint8), 'Expected number to be in range [0..255], got 256'); }); test('number.uint16', t => { - t.notThrows(() => m(0, m.number.uint16)); - t.notThrows(() => m(65535, m.number.uint16)); - t.throws(() => m(-1, m.number.uint16), 'Expected number to be in range [0..65535], got -1'); - t.throws(() => m(1.5, m.number.uint16), 'Expected number to be an integer, got 1.5'); - t.throws(() => m(65536, m.number.uint16), 'Expected number to be in range [0..65535], got 65536'); + t.notThrows(() => ow(0, ow.number.uint16)); + t.notThrows(() => ow(65535, ow.number.uint16)); + t.throws(() => ow(-1, ow.number.uint16), 'Expected number to be in range [0..65535], got -1'); + t.throws(() => ow(1.5, ow.number.uint16), 'Expected number to be an integer, got 1.5'); + t.throws(() => ow(65536, ow.number.uint16), 'Expected number to be in range [0..65535], got 65536'); }); test('number.uint32', t => { - t.notThrows(() => m(0, m.number.uint32)); - t.notThrows(() => m(4294967295, m.number.uint32)); - t.throws(() => m(-1, m.number.uint32), 'Expected number to be in range [0..4294967295], got -1'); - t.throws(() => m(1.5, m.number.uint32), 'Expected number to be an integer, got 1.5'); - t.throws(() => m(4294967296, m.number.uint32), 'Expected number to be in range [0..4294967295], got 4294967296'); + t.notThrows(() => ow(0, ow.number.uint32)); + t.notThrows(() => ow(4294967295, ow.number.uint32)); + t.throws(() => ow(-1, ow.number.uint32), 'Expected number to be in range [0..4294967295], got -1'); + t.throws(() => ow(1.5, ow.number.uint32), 'Expected number to be an integer, got 1.5'); + t.throws(() => ow(4294967296, ow.number.uint32), 'Expected number to be in range [0..4294967295], got 4294967296'); }); test('number.int8', t => { - t.notThrows(() => m(-128, m.number.int8)); - t.notThrows(() => m(127, m.number.int8)); - t.throws(() => m(-129, m.number.int8), 'Expected number to be in range [-128..127], got -129'); - t.throws(() => m(1.5, m.number.int8), 'Expected number to be an integer, got 1.5'); - t.throws(() => m(128, m.number.int8), 'Expected number to be in range [-128..127], got 128'); + t.notThrows(() => ow(-128, ow.number.int8)); + t.notThrows(() => ow(127, ow.number.int8)); + t.throws(() => ow(-129, ow.number.int8), 'Expected number to be in range [-128..127], got -129'); + t.throws(() => ow(1.5, ow.number.int8), 'Expected number to be an integer, got 1.5'); + t.throws(() => ow(128, ow.number.int8), 'Expected number to be in range [-128..127], got 128'); }); test('number.int16', t => { - t.notThrows(() => m(-32768, m.number.int16)); - t.notThrows(() => m(32767, m.number.int16)); - t.throws(() => m(-32769, m.number.int16), 'Expected number to be in range [-32768..32767], got -32769'); - t.throws(() => m(1.5, m.number.int16), 'Expected number to be an integer, got 1.5'); - t.throws(() => m(32768, m.number.int16), 'Expected number to be in range [-32768..32767], got 32768'); + t.notThrows(() => ow(-32768, ow.number.int16)); + t.notThrows(() => ow(32767, ow.number.int16)); + t.throws(() => ow(-32769, ow.number.int16), 'Expected number to be in range [-32768..32767], got -32769'); + t.throws(() => ow(1.5, ow.number.int16), 'Expected number to be an integer, got 1.5'); + t.throws(() => ow(32768, ow.number.int16), 'Expected number to be in range [-32768..32767], got 32768'); }); test('number.int32', t => { - t.notThrows(() => m(-2147483648, m.number.int32)); - t.notThrows(() => m(2147483647, m.number.int32)); - t.throws(() => m(-2147483649, m.number.int32), 'Expected number to be in range [-2147483648..2147483647], got -2147483649'); - t.throws(() => m(1.5, m.number.int32), 'Expected number to be an integer, got 1.5'); - t.throws(() => m(2147483648, m.number.int32), 'Expected number to be in range [-2147483648..2147483647], got 2147483648'); + t.notThrows(() => ow(-2147483648, ow.number.int32)); + t.notThrows(() => ow(2147483647, ow.number.int32)); + t.throws(() => ow(-2147483649, ow.number.int32), 'Expected number to be in range [-2147483648..2147483647], got -2147483649'); + t.throws(() => ow(1.5, ow.number.int32), 'Expected number to be an integer, got 1.5'); + t.throws(() => ow(2147483648, ow.number.int32), 'Expected number to be in range [-2147483648..2147483647], got 2147483648'); }); diff --git a/source/test/object.ts b/source/test/object.ts index 4c753a2..53d7d63 100644 --- a/source/test/object.ts +++ b/source/test/object.ts @@ -1,80 +1,80 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; -class Unicorn {} // tslint:disable-line +class Unicorn {} // tslint:disable-line test('object', t => { - t.notThrows(() => m({}, m.object)); - t.notThrows(() => m(new Error('foo'), m.object)); - t.throws(() => m('foo' as any, m.object), 'Expected argument to be of type `object` but received type `string`'); - t.throws(() => m('foo' as any, 'foo', m.object), 'Expected `foo` to be of type `object` but received type `string`'); - t.throws(() => m(1 as any, m.object), 'Expected argument to be of type `object` but received type `number`'); + t.notThrows(() => ow({}, ow.object)); + t.notThrows(() => ow(new Error('foo'), ow.object)); + t.throws(() => ow('foo' as any, ow.object), 'Expected argument to be of type `object` but received type `string`'); + t.throws(() => ow('foo' as any, 'foo', ow.object), 'Expected `foo` to be of type `object` but received type `string`'); + t.throws(() => ow(1 as any, ow.object), 'Expected argument to be of type `object` but received type `number`'); }); test('object.plain', t => { - t.notThrows(() => m({}, m.object.plain)); - t.throws(() => m(new Error('foo'), m.object.plain), 'Expected object to be a plain object'); - t.throws(() => m(new Error('foo'), 'foo', m.object.plain), 'Expected object `foo` to be a plain object'); + t.notThrows(() => ow({}, ow.object.plain)); + t.throws(() => ow(new Error('foo'), ow.object.plain), 'Expected object to be a plain object'); + t.throws(() => ow(new Error('foo'), 'foo', ow.object.plain), 'Expected object `foo` to be a plain object'); }); test('object.empty', t => { - t.notThrows(() => m({}, m.object.empty)); - t.throws(() => m({unicorn: '🦄'}, m.object.empty), 'Expected object to be empty, got `{"unicorn":"🦄"}`'); + t.notThrows(() => ow({}, ow.object.empty)); + t.throws(() => ow({unicorn: '🦄'}, ow.object.empty), 'Expected object to be empty, got `{"unicorn":"🦄"}`'); }); test('object.nonEmpty', t => { - t.notThrows(() => m({unicorn: '🦄'}, m.object.nonEmpty)); - t.throws(() => m({}, m.object.nonEmpty), 'Expected object to not be empty'); + t.notThrows(() => ow({unicorn: '🦄'}, ow.object.nonEmpty)); + t.throws(() => ow({}, ow.object.nonEmpty), 'Expected object to not be empty'); }); test('object.valuesOfType', t => { - t.notThrows(() => m({unicorn: '🦄'}, m.object.valuesOfType(m.string))); - t.notThrows(() => m({unicorn: '🦄', rainbow: '🌈'}, m.object.valuesOfType(m.string))); - t.notThrows(() => m({unicorn: 1, rainbow: 2}, m.object.valuesOfType(m.number))); - t.throws(() => m({unicorn: '🦄', rainbow: 2}, m.object.valuesOfType(m.string)), '(object) Expected argument to be of type `string` but received type `number`'); - t.throws(() => m({unicorn: '🦄', rainbow: 2}, 'foo', m.object.valuesOfType(m.string)), '(object `foo`) Expected argument to be of type `string` but received type `number`'); - t.throws(() => m({unicorn: 'a', rainbow: 'b'}, m.object.valuesOfType(m.string.minLength(2))), '(object) Expected string to have a minimum length of `2`, got `a`'); + t.notThrows(() => ow({unicorn: '🦄'}, ow.object.valuesOfType(ow.string))); + t.notThrows(() => ow({unicorn: '🦄', rainbow: '🌈'}, ow.object.valuesOfType(ow.string))); + t.notThrows(() => ow({unicorn: 1, rainbow: 2}, ow.object.valuesOfType(ow.number))); + t.throws(() => ow({unicorn: '🦄', rainbow: 2}, ow.object.valuesOfType(ow.string)), '(object) Expected argument to be of type `string` but received type `number`'); + t.throws(() => ow({unicorn: '🦄', rainbow: 2}, 'foo', ow.object.valuesOfType(ow.string)), '(object `foo`) Expected argument to be of type `string` but received type `number`'); + t.throws(() => ow({unicorn: 'a', rainbow: 'b'}, ow.object.valuesOfType(ow.string.minLength(2))), '(object) Expected string to have a minimum length of `2`, got `a`'); }); test('object.valuesOfTypeDeep', t => { - t.notThrows(() => m({unicorn: '🦄'}, m.object.deepValuesOfType(m.string))); - t.notThrows(() => m({unicorn: '🦄', rainbow: '🌈'}, m.object.deepValuesOfType(m.string))); - t.notThrows(() => m({unicorn: {key: '🦄', value: '🌈'}}, m.object.deepValuesOfType(m.string))); - t.notThrows(() => m({a: {b: {c: {d: 1}, e: 2}, f: 3}}, m.object.deepValuesOfType(m.number))); - t.throws(() => m({unicorn: {key: '🦄', value: 1}}, m.object.deepValuesOfType(m.string)), '(object) Expected argument to be of type `string` but received type `number`'); - t.throws(() => m({unicorn: {key: '🦄', value: 1}}, 'foo', m.object.deepValuesOfType(m.string)), '(object `foo`) Expected argument to be of type `string` but received type `number`'); - t.throws(() => m({a: {b: {c: {d: 1}, e: '2'}, f: 3}}, m.object.deepValuesOfType(m.number)), '(object) Expected argument to be of type `number` but received type `string`'); + t.notThrows(() => ow({unicorn: '🦄'}, ow.object.deepValuesOfType(ow.string))); + t.notThrows(() => ow({unicorn: '🦄', rainbow: '🌈'}, ow.object.deepValuesOfType(ow.string))); + t.notThrows(() => ow({unicorn: {key: '🦄', value: '🌈'}}, ow.object.deepValuesOfType(ow.string))); + t.notThrows(() => ow({a: {b: {c: {d: 1}, e: 2}, f: 3}}, ow.object.deepValuesOfType(ow.number))); + t.throws(() => ow({unicorn: {key: '🦄', value: 1}}, ow.object.deepValuesOfType(ow.string)), '(object) Expected argument to be of type `string` but received type `number`'); + t.throws(() => ow({unicorn: {key: '🦄', value: 1}}, 'foo', ow.object.deepValuesOfType(ow.string)), '(object `foo`) Expected argument to be of type `string` but received type `number`'); + t.throws(() => ow({a: {b: {c: {d: 1}, e: '2'}, f: 3}}, ow.object.deepValuesOfType(ow.number)), '(object) Expected argument to be of type `number` but received type `string`'); }); test('object.deepEqual', t => { - t.notThrows(() => m({unicorn: '🦄'}, m.object.deepEqual({unicorn: '🦄'}))); - t.notThrows(() => m({unicorn: '🦄', rain: {bow: '🌈'}}, m.object.deepEqual({unicorn: '🦄', rain: {bow: '🌈'}}))); - t.throws(() => m({unicorn: '🦄'}, m.object.deepEqual({rainbow: '🌈'})), 'Expected object to be deeply equal to `{"rainbow":"🌈"}`, got `{"unicorn":"🦄"}`'); + t.notThrows(() => ow({unicorn: '🦄'}, ow.object.deepEqual({unicorn: '🦄'}))); + t.notThrows(() => ow({unicorn: '🦄', rain: {bow: '🌈'}}, ow.object.deepEqual({unicorn: '🦄', rain: {bow: '🌈'}}))); + t.throws(() => ow({unicorn: '🦄'}, ow.object.deepEqual({rainbow: '🌈'})), 'Expected object to be deeply equal to `{"rainbow":"🌈"}`, got `{"unicorn":"🦄"}`'); }); test('object.instanceOf', t => { - t.notThrows(() => m(new Error('🦄'), m.object.instanceOf(Error))); - t.notThrows(() => m(new Unicorn(), m.object.instanceOf(Unicorn))); - t.throws(() => m(new Unicorn(), m.object.instanceOf(Error)), 'Expected object `Unicorn` to be of type `Error`'); - t.throws(() => m(new Unicorn(), 'foo', m.object.instanceOf(Error)), 'Expected object `foo` `Unicorn` to be of type `Error`'); - t.throws(() => m(new Error('🦄'), m.object.instanceOf(Unicorn)), 'Expected object `Error` to be of type `Unicorn`'); - t.throws(() => m({unicorn: '🦄'}, m.object.instanceOf(Unicorn)), 'Expected object `{"unicorn":"🦄"}` to be of type `Unicorn`'); + t.notThrows(() => ow(new Error('🦄'), ow.object.instanceOf(Error))); + t.notThrows(() => ow(new Unicorn(), ow.object.instanceOf(Unicorn))); + t.throws(() => ow(new Unicorn(), ow.object.instanceOf(Error)), 'Expected object `Unicorn` to be of type `Error`'); + t.throws(() => ow(new Unicorn(), 'foo', ow.object.instanceOf(Error)), 'Expected object `foo` `Unicorn` to be of type `Error`'); + t.throws(() => ow(new Error('🦄'), ow.object.instanceOf(Unicorn)), 'Expected object `Error` to be of type `Unicorn`'); + t.throws(() => ow({unicorn: '🦄'}, ow.object.instanceOf(Unicorn)), 'Expected object `{"unicorn":"🦄"}` to be of type `Unicorn`'); }); test('object.hasKeys', t => { - t.notThrows(() => m({unicorn: '🦄'}, m.object.hasKeys('unicorn'))); - t.notThrows(() => m({unicorn: {value: '🦄'}}, m.object.hasKeys('unicorn'))); - t.notThrows(() => m({unicorn: {value: '🦄'}}, m.object.hasKeys('unicorn.value'))); - t.notThrows(() => m({unicorn: '🦄', rainbow: '🌈'}, m.object.hasKeys('unicorn', 'rainbow'))); - t.throws(() => m({unicorn: '🦄'}, m.object.hasKeys('unicorn', 'rainbow')), 'Expected object to have keys `["rainbow"]`'); - t.throws(() => m({unicorn: {value: '🦄'}}, m.object.hasKeys('unicorn.foo')), 'Expected object to have keys `["unicorn.foo"]`'); + t.notThrows(() => ow({unicorn: '🦄'}, ow.object.hasKeys('unicorn'))); + t.notThrows(() => ow({unicorn: {value: '🦄'}}, ow.object.hasKeys('unicorn'))); + t.notThrows(() => ow({unicorn: {value: '🦄'}}, ow.object.hasKeys('unicorn.value'))); + t.notThrows(() => ow({unicorn: '🦄', rainbow: '🌈'}, ow.object.hasKeys('unicorn', 'rainbow'))); + t.throws(() => ow({unicorn: '🦄'}, ow.object.hasKeys('unicorn', 'rainbow')), 'Expected object to have keys `["rainbow"]`'); + t.throws(() => ow({unicorn: {value: '🦄'}}, ow.object.hasKeys('unicorn.foo')), 'Expected object to have keys `["unicorn.foo"]`'); }); test('object.hasAnyKeys', t => { - t.notThrows(() => m({unicorn: '🦄'}, m.object.hasAnyKeys('unicorn', 'rainbow', 'foo.bar'))); - t.notThrows(() => m({unicorn: {value: '🦄'}}, m.object.hasAnyKeys('unicorn', 'rainbow'))); - t.notThrows(() => m({unicorn: {value: '🦄'}}, m.object.hasAnyKeys('unicorn.value', 'rainbow'))); - t.notThrows(() => m({unicorn: '🦄', rainbow: '🌈'}, m.object.hasAnyKeys('unicorn'))); - t.throws(() => m({unicorn: '🦄'}, m.object.hasAnyKeys('foo')), 'Expected object to have any key of `["foo"]`'); - t.throws(() => m({unicorn: '🦄'}, m.object.hasAnyKeys('unicorn.value')), 'Expected object to have any key of `["unicorn.value"]`'); + t.notThrows(() => ow({unicorn: '🦄'}, ow.object.hasAnyKeys('unicorn', 'rainbow', 'foo.bar'))); + t.notThrows(() => ow({unicorn: {value: '🦄'}}, ow.object.hasAnyKeys('unicorn', 'rainbow'))); + t.notThrows(() => ow({unicorn: {value: '🦄'}}, ow.object.hasAnyKeys('unicorn.value', 'rainbow'))); + t.notThrows(() => ow({unicorn: '🦄', rainbow: '🌈'}, ow.object.hasAnyKeys('unicorn'))); + t.throws(() => ow({unicorn: '🦄'}, ow.object.hasAnyKeys('foo')), 'Expected object to have any key of `["foo"]`'); + t.throws(() => ow({unicorn: '🦄'}, ow.object.hasAnyKeys('unicorn.value')), 'Expected object to have any key of `["unicorn.value"]`'); }); diff --git a/source/test/optional.ts b/source/test/optional.ts index 17938b2..8ae5563 100644 --- a/source/test/optional.ts +++ b/source/test/optional.ts @@ -1,10 +1,10 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('optional', t => { - t.notThrows(() => m(1, m.optional.number)); - t.notThrows(() => m(undefined, m.optional.number)); - t.notThrows(() => m(undefined, m.optional.any(m.string, m.number))); - t.throws(() => m(null, m.optional.number), 'Expected argument to be of type `number` but received type `null`'); - t.throws(() => m('1' as any, m.optional.number), 'Expected argument to be of type `number` but received type `string`'); + t.notThrows(() => ow(1, ow.optional.number)); + t.notThrows(() => ow(undefined, ow.optional.number)); + t.notThrows(() => ow(undefined, ow.optional.any(ow.string, ow.number))); + t.throws(() => 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`'); }); diff --git a/source/test/promise.ts b/source/test/promise.ts index d555074..41b6bff 100644 --- a/source/test/promise.ts +++ b/source/test/promise.ts @@ -1,10 +1,10 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('promise', t => { - t.notThrows(() => m(Promise.resolve(), m.promise)); - t.notThrows(() => m(new Promise(resolve => resolve()), m.promise)); - t.throws(() => m('foo' as any, m.promise), 'Expected argument to be of type `Promise` but received type `string`'); - t.throws(() => m('foo' as any, 'foo', m.promise), 'Expected `foo` to be of type `Promise` but received type `string`'); - t.throws(() => m(12 as any, m.promise), 'Expected argument to be of type `Promise` but received type `number`'); + t.notThrows(() => ow(Promise.resolve(), ow.promise)); + t.notThrows(() => ow(new Promise(resolve => resolve()), ow.promise)); + t.throws(() => ow('foo' as any, ow.promise), 'Expected argument to be of type `Promise` but received type `string`'); + t.throws(() => ow('foo' as any, 'foo', ow.promise), 'Expected `foo` to be of type `Promise` but received type `string`'); + t.throws(() => ow(12 as any, ow.promise), 'Expected argument to be of type `Promise` but received type `number`'); }); diff --git a/source/test/regexp.ts b/source/test/regexp.ts index 1ee534e..1170456 100644 --- a/source/test/regexp.ts +++ b/source/test/regexp.ts @@ -1,10 +1,10 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('regExp', t => { - t.notThrows(() => m(/\d/, m.regExp)); - t.notThrows(() => m(new RegExp('\d'), m.regExp)); - t.throws(() => m('foo' as any, m.regExp), 'Expected argument to be of type `RegExp` but received type `string`'); - t.throws(() => m('foo' as any, 'foo', m.regExp), 'Expected `foo` to be of type `RegExp` but received type `string`'); - t.throws(() => m(12 as any, m.regExp), 'Expected argument to be of type `RegExp` but received type `number`'); + t.notThrows(() => ow(/\d/, ow.regExp)); + t.notThrows(() => ow(new RegExp('\d'), ow.regExp)); + t.throws(() => ow('foo' as any, ow.regExp), 'Expected argument to be of type `RegExp` but received type `string`'); + t.throws(() => ow('foo' as any, 'foo', ow.regExp), 'Expected `foo` to be of type `RegExp` but received type `string`'); + t.throws(() => ow(12 as any, ow.regExp), 'Expected argument to be of type `RegExp` but received type `number`'); }); diff --git a/source/test/set.ts b/source/test/set.ts index 6dc9603..c582331 100644 --- a/source/test/set.ts +++ b/source/test/set.ts @@ -1,70 +1,70 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('set', t => { - t.notThrows(() => m(new Set(), m.set)); - t.notThrows(() => m(new Set(['🦄']), m.set)); - t.throws(() => m(12 as any, m.set), 'Expected argument to be of type `Set` but received type `number`'); - t.throws(() => m(12 as any, 'foo', m.set), 'Expected `foo` to be of type `Set` but received type `number`'); + t.notThrows(() => ow(new Set(), ow.set)); + t.notThrows(() => ow(new Set(['🦄']), ow.set)); + t.throws(() => ow(12 as any, ow.set), 'Expected argument to be of type `Set` but received type `number`'); + t.throws(() => ow(12 as any, 'foo', ow.set), 'Expected `foo` to be of type `Set` but received type `number`'); }); test('set.size', t => { - t.notThrows(() => m(new Set(), m.set.size(0))); - t.notThrows(() => m(new Set(['🦄']), m.set.size(1))); - t.throws(() => m(new Set(['🦄']), m.set.size(0)), 'Expected Set to have size `0`, got `1`'); - t.throws(() => m(new Set(['🦄']), 'foo', m.set.size(0)), 'Expected Set `foo` to have size `0`, got `1`'); + t.notThrows(() => ow(new Set(), ow.set.size(0))); + t.notThrows(() => ow(new Set(['🦄']), ow.set.size(1))); + t.throws(() => ow(new Set(['🦄']), ow.set.size(0)), 'Expected Set to have size `0`, got `1`'); + t.throws(() => ow(new Set(['🦄']), 'foo', ow.set.size(0)), 'Expected Set `foo` to have size `0`, got `1`'); }); test('set.minSize', t => { - t.notThrows(() => m(new Set(['🦄']), m.set.minSize(1))); - t.notThrows(() => m(new Set(['🦄', '🌈']), m.set.minSize(1))); - t.throws(() => m(new Set(['🦄']), m.set.minSize(2)), 'Expected Set to have a minimum size of `2`, got `1`'); + t.notThrows(() => ow(new Set(['🦄']), ow.set.minSize(1))); + t.notThrows(() => ow(new Set(['🦄', '🌈']), ow.set.minSize(1))); + t.throws(() => ow(new Set(['🦄']), ow.set.minSize(2)), 'Expected Set to have a minimum size of `2`, got `1`'); }); test('set.maxSize', t => { - t.notThrows(() => m(new Set(['🦄']), m.set.maxSize(1))); - t.notThrows(() => m(new Set(['🦄', '🌈']), m.set.maxSize(4))); - t.throws(() => m(new Set(['🦄', '🌈']), m.set.maxSize(1)), 'Expected Set to have a maximum size of `1`, got `2`'); + t.notThrows(() => ow(new Set(['🦄']), ow.set.maxSize(1))); + t.notThrows(() => ow(new Set(['🦄', '🌈']), ow.set.maxSize(4))); + t.throws(() => ow(new Set(['🦄', '🌈']), ow.set.maxSize(1)), 'Expected Set to have a maximum size of `1`, got `2`'); }); test('set.hasKeys', t => { - t.notThrows(() => m(new Set(['unicorn']), m.set.has('unicorn'))); - t.notThrows(() => m(new Set(['unicorn', 'rainbow']), m.set.has('unicorn', 'rainbow'))); - t.notThrows(() => m(new Set([1, 2]), m.set.has(1, 2))); - t.throws(() => m(new Set(['unicorn', 'rainbow']), m.set.has('foo')), 'Expected Set to have items `["foo"]`'); - t.throws(() => m(new Set(['unicorn', 'foo']), m.set.has('foo', 'bar')), 'Expected Set to have items `["bar"]`'); - t.throws(() => m(new Set([2, 4]), m.set.has(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)), 'Expected Set to have items `[1,3,5,6,7]`'); + t.notThrows(() => ow(new Set(['unicorn']), ow.set.has('unicorn'))); + t.notThrows(() => ow(new Set(['unicorn', 'rainbow']), ow.set.has('unicorn', 'rainbow'))); + t.notThrows(() => ow(new Set([1, 2]), ow.set.has(1, 2))); + t.throws(() => ow(new Set(['unicorn', 'rainbow']), ow.set.has('foo')), 'Expected Set to have items `["foo"]`'); + t.throws(() => ow(new Set(['unicorn', 'foo']), ow.set.has('foo', 'bar')), 'Expected Set to have items `["bar"]`'); + t.throws(() => ow(new Set([2, 4]), ow.set.has(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)), 'Expected Set to have items `[1,3,5,6,7]`'); }); test('set.hasAny', t => { - t.notThrows(() => m(new Set(['unicorn']), m.set.hasAny('unicorn', 'rainbow'))); - t.notThrows(() => m(new Set(['unicorn', 'rainbow']), m.set.hasAny('unicorn'))); - t.notThrows(() => m(new Set([1, 2]), m.set.hasAny(1, 2, 3, 4))); - t.throws(() => m(new Set(['unicorn', 'rainbow']), m.set.hasAny('foo')), 'Expected Set to have any item of `["foo"]`'); + t.notThrows(() => ow(new Set(['unicorn']), ow.set.hasAny('unicorn', 'rainbow'))); + t.notThrows(() => ow(new Set(['unicorn', 'rainbow']), ow.set.hasAny('unicorn'))); + t.notThrows(() => ow(new Set([1, 2]), ow.set.hasAny(1, 2, 3, 4))); + t.throws(() => ow(new Set(['unicorn', 'rainbow']), ow.set.hasAny('foo')), 'Expected Set to have any item of `["foo"]`'); }); test('set.ofType', t => { - t.notThrows(() => m(new Set(['unicorn']), m.set.ofType(m.string))); - t.notThrows(() => m(new Set(['unicorn', 'rainbow']), m.set.ofType(m.string.minLength(3)))); - t.notThrows(() => m(new Set([1]), m.set.ofType(m.number))); - t.throws(() => m(new Set(['unicorn']), m.set.ofType(m.number)), '(Set) Expected argument to be of type `number` but received type `string`'); - t.throws(() => m(new Set(['unicorn']), 'foo', m.set.ofType(m.number)), '(Set `foo`) Expected argument to be of type `number` but received type `string`'); + t.notThrows(() => ow(new Set(['unicorn']), ow.set.ofType(ow.string))); + t.notThrows(() => ow(new Set(['unicorn', 'rainbow']), ow.set.ofType(ow.string.minLength(3)))); + t.notThrows(() => ow(new Set([1]), ow.set.ofType(ow.number))); + t.throws(() => ow(new Set(['unicorn']), ow.set.ofType(ow.number)), '(Set) Expected argument to be of type `number` but received type `string`'); + t.throws(() => ow(new Set(['unicorn']), 'foo', ow.set.ofType(ow.number)), '(Set `foo`) Expected argument to be of type `number` but received type `string`'); }); test('set.empty', t => { - t.notThrows(() => m(new Set(), m.set.empty)); - t.notThrows(() => m(new Set([]), m.set.empty)); - t.throws(() => m(new Set(['unicorn']), m.set.empty), 'Expected Set to be empty, got `["unicorn"]`'); + t.notThrows(() => ow(new Set(), ow.set.empty)); + t.notThrows(() => ow(new Set([]), ow.set.empty)); + t.throws(() => ow(new Set(['unicorn']), ow.set.empty), 'Expected Set to be empty, got `["unicorn"]`'); }); test('set.notEmpty', t => { - t.notThrows(() => m(new Set(['unicorn']), m.set.nonEmpty)); - t.throws(() => m(new Set(), m.set.nonEmpty), 'Expected Set to not be empty'); + t.notThrows(() => ow(new Set(['unicorn']), ow.set.nonEmpty)); + t.throws(() => ow(new Set(), ow.set.nonEmpty), 'Expected Set to not be empty'); }); test('set.deepEqual', t => { - t.notThrows(() => m(new Set(['unicorn']), m.set.deepEqual(new Set(['unicorn'])))); - t.notThrows(() => m(new Set([{foo: 'bar'}]), m.set.deepEqual(new Set([{foo: 'bar'}])))); - t.throws(() => m(new Set(['unicorn']), m.set.deepEqual(new Set(['rainbow']))), 'Expected Set to be deeply equal to `["rainbow"]`, got `["unicorn"]`'); - t.throws(() => m(new Set([{foo: 'bar'}]), m.set.deepEqual(new Set([{foo: 'baz'}]))), 'Expected Set to be deeply equal to `[{"foo":"baz"}]`, got `[{"foo":"bar"}]`'); + t.notThrows(() => ow(new Set(['unicorn']), ow.set.deepEqual(new Set(['unicorn'])))); + t.notThrows(() => ow(new Set([{foo: 'bar'}]), ow.set.deepEqual(new Set([{foo: 'bar'}])))); + t.throws(() => ow(new Set(['unicorn']), ow.set.deepEqual(new Set(['rainbow']))), 'Expected Set to be deeply equal to `["rainbow"]`, got `["unicorn"]`'); + t.throws(() => ow(new Set([{foo: 'bar'}]), ow.set.deepEqual(new Set([{foo: 'baz'}]))), 'Expected Set to be deeply equal to `[{"foo":"baz"}]`, got `[{"foo":"bar"}]`'); }); diff --git a/source/test/string.ts b/source/test/string.ts index 9acdf48..0e1e5e7 100644 --- a/source/test/string.ts +++ b/source/test/string.ts @@ -1,126 +1,126 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('string', t => { const bar: any = 12; - t.notThrows(() => m('foo', m.string)); - t.throws(() => m(12 as any, m.string), 'Expected argument to be of type `string` but received type `number`'); - t.throws(() => m(12 as any, 'bar', m.string), 'Expected `bar` to be of type `string` but received type `number`'); - t.throws(() => m(bar, m.string), 'Expected `bar` to be of type `string` but received type `number`'); + t.notThrows(() => ow('foo', ow.string)); + t.throws(() => ow(12 as any, ow.string), 'Expected argument to be of type `string` but received type `number`'); + t.throws(() => ow(12 as any, 'bar', ow.string), 'Expected `bar` to be of type `string` but received type `number`'); + t.throws(() => ow(bar, ow.string), 'Expected `bar` to be of type `string` but received type `number`'); }); test('string.length', t => { - t.notThrows(() => m('foo', m.string.length(3))); - t.notThrows(() => m('foobar', m.string.length(6))); - t.throws(() => m('foo' as any, m.string.length(4)), 'Expected string to have length `4`, got `foo`'); - t.throws(() => m('foo' as any, 'foo', m.string.length(4)), 'Expected string `foo` to have length `4`, got `foo`'); + t.notThrows(() => ow('foo', ow.string.length(3))); + t.notThrows(() => ow('foobar', ow.string.length(6))); + t.throws(() => ow('foo' as any, ow.string.length(4)), 'Expected string to have length `4`, got `foo`'); + t.throws(() => ow('foo' as any, 'foo', ow.string.length(4)), 'Expected string `foo` to have length `4`, got `foo`'); }); test('string.minLength', t => { - t.notThrows(() => m('foo', m.string.minLength(2))); - t.notThrows(() => m('foo', m.string.minLength(3))); - t.throws(() => m('foo' as any, m.string.minLength(4)), 'Expected string to have a minimum length of `4`, got `foo`'); + t.notThrows(() => ow('foo', ow.string.minLength(2))); + t.notThrows(() => ow('foo', ow.string.minLength(3))); + t.throws(() => ow('foo' as any, ow.string.minLength(4)), 'Expected string to have a minimum length of `4`, got `foo`'); }); test('string.maxLength', t => { - t.notThrows(() => m('foo', m.string.maxLength(3))); - t.notThrows(() => m('foo', m.string.maxLength(5))); - t.throws(() => m('foo' as any, m.string.maxLength(2)), 'Expected string to have a maximum length of `2`, got `foo`'); + t.notThrows(() => ow('foo', ow.string.maxLength(3))); + t.notThrows(() => ow('foo', ow.string.maxLength(5))); + t.throws(() => ow('foo' as any, ow.string.maxLength(2)), 'Expected string to have a maximum length of `2`, got `foo`'); }); test('string.matches', t => { - t.notThrows(() => m('foo', m.string.matches(/^f.o$/))); - t.notThrows(() => m('Foo', m.string.matches(/^f.o$/i))); - t.throws(() => m('Foo' as any, m.string.matches(/^f.o$/)), 'Expected string to match `/^f.o$/`, got `Foo`'); - t.throws(() => m('bar' as any, m.string.matches(/^f.o$/i)), 'Expected string to match `/^f.o$/i`, got `bar`'); + t.notThrows(() => ow('foo', ow.string.matches(/^f.o$/))); + t.notThrows(() => ow('Foo', ow.string.matches(/^f.o$/i))); + t.throws(() => ow('Foo' as any, ow.string.matches(/^f.o$/)), 'Expected string to match `/^f.o$/`, got `Foo`'); + t.throws(() => ow('bar' as any, ow.string.matches(/^f.o$/i)), 'Expected string to match `/^f.o$/i`, got `bar`'); }); test('string.startsWith', t => { - t.notThrows(() => m('foo', m.string.startsWith('fo'))); - t.notThrows(() => m('foo', m.string.startsWith('f'))); - t.throws(() => m('foo' as any, m.string.startsWith('oo')), 'Expected string to start with `oo`, got `foo`'); - t.throws(() => m('foo' as any, m.string.startsWith('b')), 'Expected string to start with `b`, got `foo`'); + t.notThrows(() => ow('foo', ow.string.startsWith('fo'))); + t.notThrows(() => ow('foo', ow.string.startsWith('f'))); + t.throws(() => ow('foo' as any, ow.string.startsWith('oo')), 'Expected string to start with `oo`, got `foo`'); + t.throws(() => ow('foo' as any, ow.string.startsWith('b')), 'Expected string to start with `b`, got `foo`'); }); test('string.endsWith', t => { - t.notThrows(() => m('foo', m.string.endsWith('oo'))); - t.notThrows(() => m('foo', m.string.endsWith('o'))); - t.throws(() => m('foo' as any, m.string.endsWith('fo')), 'Expected string to end with `fo`, got `foo`'); - t.throws(() => m('foo' as any, m.string.endsWith('ar')), 'Expected string to end with `ar`, got `foo`'); + t.notThrows(() => ow('foo', ow.string.endsWith('oo'))); + t.notThrows(() => ow('foo', ow.string.endsWith('o'))); + t.throws(() => ow('foo' as any, ow.string.endsWith('fo')), 'Expected string to end with `fo`, got `foo`'); + t.throws(() => ow('foo' as any, ow.string.endsWith('ar')), 'Expected string to end with `ar`, got `foo`'); }); test('string.includes', t => { - t.notThrows(() => m('foo', m.string.includes('fo'))); - t.throws(() => m('foo' as any, m.string.includes('bar')), 'Expected string to include `bar`, got `foo`'); + t.notThrows(() => ow('foo', ow.string.includes('fo'))); + t.throws(() => ow('foo' as any, ow.string.includes('bar')), 'Expected string to include `bar`, got `foo`'); }); test('string.oneOf', t => { - t.notThrows(() => m('foo', m.string.oneOf(['foo', 'bar']))); - t.throws(() => m('foo', m.string.oneOf(['unicorn', 'rainbow'])), 'Expected string to be one of `["unicorn","rainbow"]`, got `foo`'); - t.throws(() => m('foo', 'hello', m.string.oneOf(['unicorn', 'rainbow'])), 'Expected string `hello` to be one of `["unicorn","rainbow"]`, got `foo`'); - t.throws(() => m('foo', m.string.oneOf(['a', 'b', 'c', 'd', 'e'])), 'Expected string to be one of `["a","b","c","d","e"]`, got `foo`'); - t.throws(() => m('foo', m.string.oneOf(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13'])), 'Expected string to be one of `["1","2","3","4","5","6","7","8","9","10",…+3 more]`, got `foo`'); + t.notThrows(() => ow('foo', ow.string.oneOf(['foo', 'bar']))); + t.throws(() => ow('foo', ow.string.oneOf(['unicorn', 'rainbow'])), 'Expected string to be one of `["unicorn","rainbow"]`, got `foo`'); + t.throws(() => ow('foo', 'hello', ow.string.oneOf(['unicorn', 'rainbow'])), 'Expected string `hello` to be one of `["unicorn","rainbow"]`, got `foo`'); + t.throws(() => ow('foo', ow.string.oneOf(['a', 'b', 'c', 'd', 'e'])), 'Expected string to be one of `["a","b","c","d","e"]`, got `foo`'); + t.throws(() => ow('foo', ow.string.oneOf(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13'])), 'Expected string to be one of `["1","2","3","4","5","6","7","8","9","10",…+3 more]`, got `foo`'); }); test('string.empty', t => { - t.notThrows(() => m('', m.string.empty)); - t.throws(() => m('foo' as any, m.string.empty), 'Expected string to be empty, got `foo`'); + t.notThrows(() => ow('', ow.string.empty)); + t.throws(() => ow('foo' as any, ow.string.empty), 'Expected string to be empty, got `foo`'); }); test('string.nonEmpty', t => { - t.notThrows(() => m('foo', m.string.nonEmpty)); - t.throws(() => m('' as any, m.string.nonEmpty), 'Expected string to not be empty'); + t.notThrows(() => ow('foo', ow.string.nonEmpty)); + t.throws(() => ow('' as any, ow.string.nonEmpty), 'Expected string to not be empty'); }); test('string.equals', t => { - t.notThrows(() => m('foo', m.string.equals('foo'))); - t.throws(() => m('bar' as any, m.string.equals('foo')), 'Expected string to be equal to `foo`, got `bar`'); + t.notThrows(() => ow('foo', ow.string.equals('foo'))); + t.throws(() => ow('bar' as any, ow.string.equals('foo')), 'Expected string to be equal to `foo`, got `bar`'); }); test('string.alphabetical', t => { - t.notThrows(() => m('foo', m.string.alphabetical)); - t.notThrows(() => m('FOO', m.string.alphabetical)); - t.throws(() => m('foo123', m.string.alphabetical), 'Expected string to be alphabetical, got `foo123`'); - t.throws(() => m('', m.string.alphabetical), 'Expected string to be alphabetical, got ``'); + t.notThrows(() => ow('foo', ow.string.alphabetical)); + t.notThrows(() => ow('FOO', ow.string.alphabetical)); + t.throws(() => ow('foo123', ow.string.alphabetical), 'Expected string to be alphabetical, got `foo123`'); + t.throws(() => ow('', ow.string.alphabetical), 'Expected string to be alphabetical, got ``'); }); test('string.alphanumeric', t => { - t.notThrows(() => m('Foo123', m.string.alphanumeric)); - t.throws(() => m('Foo123!' as any, m.string.alphanumeric), 'Expected string to be alphanumeric, got `Foo123!`'); + t.notThrows(() => ow('Foo123', ow.string.alphanumeric)); + t.throws(() => ow('Foo123!' as any, ow.string.alphanumeric), 'Expected string to be alphanumeric, got `Foo123!`'); }); test('string.numeric', t => { - t.notThrows(() => m('123', m.string.numeric)); - t.notThrows(() => m('-123', m.string.numeric)); - t.notThrows(() => m('+123', m.string.numeric)); - t.throws(() => m('Foo123', m.string.numeric), 'Expected string to be numeric, got `Foo123`'); - t.throws(() => m('++123', m.string.numeric), 'Expected string to be numeric, got `++123`'); - t.throws(() => m('1+1', m.string.numeric), 'Expected string to be numeric, got `1+1`'); - t.throws(() => m('11-', m.string.numeric), 'Expected string to be numeric, got `11-`'); - t.throws(() => m('--123', m.string.numeric), 'Expected string to be numeric, got `--123`'); - t.throws(() => m('+-123', m.string.numeric), 'Expected string to be numeric, got `+-123`'); + t.notThrows(() => ow('123', ow.string.numeric)); + t.notThrows(() => ow('-123', ow.string.numeric)); + t.notThrows(() => ow('+123', ow.string.numeric)); + t.throws(() => ow('Foo123', ow.string.numeric), 'Expected string to be numeric, got `Foo123`'); + t.throws(() => ow('++123', ow.string.numeric), 'Expected string to be numeric, got `++123`'); + t.throws(() => ow('1+1', ow.string.numeric), 'Expected string to be numeric, got `1+1`'); + t.throws(() => ow('11-', ow.string.numeric), 'Expected string to be numeric, got `11-`'); + t.throws(() => ow('--123', ow.string.numeric), 'Expected string to be numeric, got `--123`'); + t.throws(() => ow('+-123', ow.string.numeric), 'Expected string to be numeric, got `+-123`'); }); test('string.date', t => { - t.notThrows(() => m('2017-03-02', m.string.date)); - t.notThrows(() => m('2017-03-02T10:00:00Z', m.string.date)); - t.throws(() => m('foo' as any, m.string.date), 'Expected string to be a date, got `foo`'); - t.throws(() => m('foo' as any, 'bar', m.string.date), 'Expected string `bar` to be a date, got `foo`'); + t.notThrows(() => ow('2017-03-02', ow.string.date)); + t.notThrows(() => ow('2017-03-02T10:00:00Z', ow.string.date)); + t.throws(() => ow('foo' as any, ow.string.date), 'Expected string to be a date, got `foo`'); + t.throws(() => ow('foo' as any, 'bar', ow.string.date), 'Expected string `bar` to be a date, got `foo`'); }); test('string.lowercase', t => { - t.notThrows(() => m('foo', m.string.lowercase)); - t.notThrows(() => m('foo123', m.string.lowercase)); - t.notThrows(() => m('123', m.string.lowercase)); - t.throws(() => m('FOO', m.string.lowercase), 'Expected string to be lowercase, got `FOO`'); - t.throws(() => m('', m.string.lowercase), 'Expected string to be lowercase, got ``'); + t.notThrows(() => ow('foo', ow.string.lowercase)); + t.notThrows(() => ow('foo123', ow.string.lowercase)); + t.notThrows(() => ow('123', ow.string.lowercase)); + t.throws(() => ow('FOO', ow.string.lowercase), 'Expected string to be lowercase, got `FOO`'); + t.throws(() => ow('', ow.string.lowercase), 'Expected string to be lowercase, got ``'); }); test('string.uppercase', t => { - t.notThrows(() => m('FOO', m.string.uppercase)); - t.notThrows(() => m('FOO123', m.string.uppercase)); - t.notThrows(() => m('123', m.string.uppercase)); - t.throws(() => m('foo', m.string.uppercase), 'Expected string to be uppercase, got `foo`'); - t.throws(() => m('', m.string.uppercase), 'Expected string to be uppercase, got ``'); + t.notThrows(() => ow('FOO', ow.string.uppercase)); + t.notThrows(() => ow('FOO123', ow.string.uppercase)); + t.notThrows(() => ow('123', ow.string.uppercase)); + t.throws(() => ow('foo', ow.string.uppercase), 'Expected string to be uppercase, got `foo`'); + t.throws(() => ow('', ow.string.uppercase), 'Expected string to be uppercase, got ``'); }); diff --git a/source/test/symbol.ts b/source/test/symbol.ts index 1997ca1..7dc0a13 100644 --- a/source/test/symbol.ts +++ b/source/test/symbol.ts @@ -1,9 +1,9 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('symbol', t => { - t.notThrows(() => m(Symbol.iterator, m.symbol)); - t.notThrows(() => m(Symbol('foo'), m.symbol)); - t.throws(() => m(12 as any, m.symbol), 'Expected argument to be of type `symbol` but received type `number`'); - t.throws(() => m(12 as any, 'foo', m.symbol), 'Expected `foo` to be of type `symbol` but received type `number`'); + t.notThrows(() => ow(Symbol.iterator, ow.symbol)); + t.notThrows(() => ow(Symbol('foo'), ow.symbol)); + t.throws(() => ow(12 as any, ow.symbol), 'Expected argument to be of type `symbol` but received type `number`'); + t.throws(() => ow(12 as any, 'foo', ow.symbol), 'Expected `foo` to be of type `symbol` but received type `number`'); }); diff --git a/source/test/test.ts b/source/test/test.ts index 0581efe..711b694 100644 --- a/source/test/test.ts +++ b/source/test/test.ts @@ -1,22 +1,22 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; import {createAnyError} from './fixtures/create-error'; test('not', t => { const foo = ''; - t.notThrows(() => m('foo!', m.string.not.alphanumeric)); - t.notThrows(() => m(1, m.number.not.infinite)); - t.notThrows(() => m(1, m.number.not.infinite.not.greaterThan(5))); - t.throws(() => m(6, m.number.not.infinite.not.greaterThan(5))); - t.notThrows(() => m('foo!', m.string.not.alphabetical)); - t.notThrows(() => m('foo!', m.string.not.alphanumeric)); - t.notThrows(() => m('foo!', 'foo', m.string.not.alphanumeric)); - t.notThrows(() => m('FOO!', m.string.not.lowercase)); - t.notThrows(() => m('foo!', m.string.not.uppercase)); - t.throws(() => m('', m.string.not.empty), '[NOT] Expected string to be empty, got ``'); - t.throws(() => m('', 'foo', m.string.not.empty), '[NOT] Expected string `foo` to be empty, got ``'); - t.throws(() => m(foo, m.string.not.empty), '[NOT] Expected string `foo` to be empty, got ``'); + t.notThrows(() => ow('foo!', ow.string.not.alphanumeric)); + t.notThrows(() => ow(1, ow.number.not.infinite)); + t.notThrows(() => ow(1, ow.number.not.infinite.not.greaterThan(5))); + t.throws(() => ow(6, ow.number.not.infinite.not.greaterThan(5))); + t.notThrows(() => ow('foo!', ow.string.not.alphabetical)); + t.notThrows(() => ow('foo!', ow.string.not.alphanumeric)); + t.notThrows(() => ow('foo!', 'foo', ow.string.not.alphanumeric)); + t.notThrows(() => ow('FOO!', ow.string.not.lowercase)); + t.notThrows(() => ow('foo!', ow.string.not.uppercase)); + t.throws(() => ow('', ow.string.not.empty), '[NOT] Expected string to be empty, got ``'); + t.throws(() => ow('', 'foo', ow.string.not.empty), '[NOT] Expected string `foo` to be empty, got ``'); + t.throws(() => ow(foo, ow.string.not.empty), '[NOT] Expected string `foo` to be empty, got ``'); }); test('is', t => { @@ -24,26 +24,26 @@ test('is', t => { return x > max || `Expected \`${x}\` to be greater than \`${max}\``; }; - t.notThrows(() => m(1, m.number.is(x => x < 10))); - t.throws(() => m(1, m.number.is(x => x > 10)), 'Expected number `1` to pass custom validation function'); - t.throws(() => m(1, 'foo', m.number.is(x => x > 10)), 'Expected number `foo` `1` to pass custom validation function'); - t.throws(() => m(5, m.number.is(x => greaterThan(10, x))), '(number) Expected `5` to be greater than `10`'); - t.throws(() => m(5, 'foo', m.number.is(x => greaterThan(10, x))), '(number `foo`) Expected `5` to be greater than `10`'); + t.notThrows(() => ow(1, ow.number.is(x => x < 10))); + t.throws(() => ow(1, ow.number.is(x => x > 10)), 'Expected number `1` to pass custom validation function'); + t.throws(() => ow(1, 'foo', ow.number.is(x => x > 10)), 'Expected number `foo` `1` to pass custom validation function'); + t.throws(() => ow(5, ow.number.is(x => greaterThan(10, x))), '(number) Expected `5` to be greater than `10`'); + t.throws(() => ow(5, 'foo', ow.number.is(x => greaterThan(10, x))), '(number `foo`) Expected `5` to be greater than `10`'); }); test('isValid', t => { - t.true(m.isValid(1, m.number)); - t.true(m.isValid(1, m.number.equal(1))); - t.true(m.isValid('foo!', m.string.not.alphanumeric)); - t.true(m.isValid('foo!', m.any(m.string, m.number))); - t.true(m.isValid(1, m.any(m.string, m.number))); - t.false(m.isValid(1 as any, m.string)); - t.false(m.isValid(1 as any, m.number.greaterThan(2))); - t.false(m.isValid(true as any, m.any(m.string, m.number))); + t.true(ow.isValid(1, ow.number)); + t.true(ow.isValid(1, ow.number.equal(1))); + t.true(ow.isValid('foo!', ow.string.not.alphanumeric)); + t.true(ow.isValid('foo!', ow.any(ow.string, ow.number))); + t.true(ow.isValid(1, ow.any(ow.string, ow.number))); + t.false(ow.isValid(1 as any, ow.string)); + t.false(ow.isValid(1 as any, ow.number.greaterThan(2))); + t.false(ow.isValid(true as any, ow.any(ow.string, ow.number))); }); test('reusable validator', t => { - const checkUsername = m.create(m.string.minLength(3)); + const checkUsername = ow.create(ow.string.minLength(3)); const value = 'x'; @@ -55,7 +55,7 @@ test('reusable validator', t => { }); test('reusable validator with label', t => { - const checkUsername = m.create('foo', m.string.minLength(3)); + const checkUsername = ow.create('foo', ow.string.minLength(3)); t.notThrows(() => checkUsername('foo')); t.notThrows(() => checkUsername('foobar')); @@ -64,7 +64,7 @@ test('reusable validator with label', t => { }); test('any-reusable validator', t => { - const checkUsername = m.create(m.any(m.string.includes('.'), m.string.minLength(3))); + const checkUsername = ow.create(ow.any(ow.string.includes('.'), ow.string.minLength(3))); t.notThrows(() => checkUsername('foo')); t.notThrows(() => checkUsername('f.')); diff --git a/source/test/typed-array.ts b/source/test/typed-array.ts index be7e7b6..c39b435 100644 --- a/source/test/typed-array.ts +++ b/source/test/typed-array.ts @@ -1,66 +1,66 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('typedArray', t => { - t.notThrows(() => m(new Int8Array(2), m.typedArray)); - t.notThrows(() => m(new Uint8Array(2), m.typedArray)); - t.notThrows(() => m(new Int32Array(2), m.typedArray)); - t.notThrows(() => m(new Float64Array(2), m.typedArray)); - t.throws(() => m('foo' as any, m.typedArray), 'Expected argument to be of type `TypedArray` but received type `string`'); - t.throws(() => m('foo' as any, 'foo', m.typedArray), 'Expected `foo` to be of type `TypedArray` but received type `string`'); - t.throws(() => m(12 as any, m.typedArray), 'Expected argument to be of type `TypedArray` but received type `number`'); + t.notThrows(() => ow(new Int8Array(2), ow.typedArray)); + t.notThrows(() => ow(new Uint8Array(2), ow.typedArray)); + t.notThrows(() => ow(new Int32Array(2), ow.typedArray)); + t.notThrows(() => ow(new Float64Array(2), ow.typedArray)); + t.throws(() => ow('foo' as any, ow.typedArray), 'Expected argument to be of type `TypedArray` but received type `string`'); + t.throws(() => ow('foo' as any, 'foo', ow.typedArray), 'Expected `foo` to be of type `TypedArray` but received type `string`'); + t.throws(() => ow(12 as any, ow.typedArray), 'Expected argument to be of type `TypedArray` but received type `number`'); }); test('int8Array', t => { - t.notThrows(() => m(new Int8Array(2), m.int8Array)); - t.throws(() => m('foo' as any, m.int8Array), 'Expected argument to be of type `Int8Array` but received type `string`'); - t.throws(() => m(12 as any, m.int8Array), 'Expected argument to be of type `Int8Array` but received type `number`'); + t.notThrows(() => ow(new Int8Array(2), ow.int8Array)); + t.throws(() => ow('foo' as any, ow.int8Array), 'Expected argument to be of type `Int8Array` but received type `string`'); + t.throws(() => ow(12 as any, ow.int8Array), 'Expected argument to be of type `Int8Array` but received type `number`'); }); test('uint8Array', t => { - t.notThrows(() => m(new Uint8Array(2), m.uint8Array)); - t.throws(() => m('foo' as any, m.uint8Array), 'Expected argument to be of type `Uint8Array` but received type `string`'); - t.throws(() => m(12 as any, m.uint8Array), 'Expected argument to be of type `Uint8Array` but received type `number`'); + t.notThrows(() => ow(new Uint8Array(2), ow.uint8Array)); + t.throws(() => ow('foo' as any, ow.uint8Array), 'Expected argument to be of type `Uint8Array` but received type `string`'); + t.throws(() => ow(12 as any, ow.uint8Array), 'Expected argument to be of type `Uint8Array` but received type `number`'); }); test('uint8ClampedArray', t => { - t.notThrows(() => m(new Uint8ClampedArray(2), m.uint8ClampedArray)); - t.throws(() => m('foo' as any, m.uint8ClampedArray), 'Expected argument to be of type `Uint8ClampedArray` but received type `string`'); - t.throws(() => m(12 as any, m.uint8ClampedArray), 'Expected argument to be of type `Uint8ClampedArray` but received type `number`'); + t.notThrows(() => ow(new Uint8ClampedArray(2), ow.uint8ClampedArray)); + t.throws(() => ow('foo' as any, ow.uint8ClampedArray), 'Expected argument to be of type `Uint8ClampedArray` but received type `string`'); + t.throws(() => ow(12 as any, ow.uint8ClampedArray), 'Expected argument to be of type `Uint8ClampedArray` but received type `number`'); }); test('int16Array', t => { - t.notThrows(() => m(new Int16Array(2), m.int16Array)); - t.throws(() => m('foo' as any, m.int16Array), 'Expected argument to be of type `Int16Array` but received type `string`'); - t.throws(() => m(12 as any, m.int16Array), 'Expected argument to be of type `Int16Array` but received type `number`'); + t.notThrows(() => ow(new Int16Array(2), ow.int16Array)); + t.throws(() => ow('foo' as any, ow.int16Array), 'Expected argument to be of type `Int16Array` but received type `string`'); + t.throws(() => ow(12 as any, ow.int16Array), 'Expected argument to be of type `Int16Array` but received type `number`'); }); test('uint16Array', t => { - t.notThrows(() => m(new Uint16Array(2), m.uint16Array)); - t.throws(() => m('foo' as any, m.uint16Array), 'Expected argument to be of type `Uint16Array` but received type `string`'); - t.throws(() => m(12 as any, m.uint16Array), 'Expected argument to be of type `Uint16Array` but received type `number`'); + t.notThrows(() => ow(new Uint16Array(2), ow.uint16Array)); + t.throws(() => ow('foo' as any, ow.uint16Array), 'Expected argument to be of type `Uint16Array` but received type `string`'); + t.throws(() => ow(12 as any, ow.uint16Array), 'Expected argument to be of type `Uint16Array` but received type `number`'); }); test('int32Array', t => { - t.notThrows(() => m(new Int32Array(2), m.int32Array)); - t.throws(() => m('foo' as any, m.int32Array), 'Expected argument to be of type `Int32Array` but received type `string`'); - t.throws(() => m(12 as any, m.int32Array), 'Expected argument to be of type `Int32Array` but received type `number`'); + t.notThrows(() => ow(new Int32Array(2), ow.int32Array)); + t.throws(() => ow('foo' as any, ow.int32Array), 'Expected argument to be of type `Int32Array` but received type `string`'); + t.throws(() => ow(12 as any, ow.int32Array), 'Expected argument to be of type `Int32Array` but received type `number`'); }); test('uint32Array', t => { - t.notThrows(() => m(new Uint32Array(2), m.uint32Array)); - t.throws(() => m('foo' as any, m.uint32Array), 'Expected argument to be of type `Uint32Array` but received type `string`'); - t.throws(() => m(12 as any, m.uint32Array), 'Expected argument to be of type `Uint32Array` but received type `number`'); + t.notThrows(() => ow(new Uint32Array(2), ow.uint32Array)); + t.throws(() => ow('foo' as any, ow.uint32Array), 'Expected argument to be of type `Uint32Array` but received type `string`'); + t.throws(() => ow(12 as any, ow.uint32Array), 'Expected argument to be of type `Uint32Array` but received type `number`'); }); test('float32Array', t => { - t.notThrows(() => m(new Float32Array(2), m.float32Array)); - t.throws(() => m('foo' as any, m.float32Array), 'Expected argument to be of type `Float32Array` but received type `string`'); - t.throws(() => m(12 as any, m.float32Array), 'Expected argument to be of type `Float32Array` but received type `number`'); + t.notThrows(() => ow(new Float32Array(2), ow.float32Array)); + t.throws(() => ow('foo' as any, ow.float32Array), 'Expected argument to be of type `Float32Array` but received type `string`'); + t.throws(() => ow(12 as any, ow.float32Array), 'Expected argument to be of type `Float32Array` but received type `number`'); }); test('float64Array', t => { - t.notThrows(() => m(new Float64Array(2), m.float64Array)); - t.throws(() => m('foo' as any, m.float64Array), 'Expected argument to be of type `Float64Array` but received type `string`'); - t.throws(() => m(12 as any, m.float64Array), 'Expected argument to be of type `Float64Array` but received type `number`'); + t.notThrows(() => ow(new Float64Array(2), ow.float64Array)); + t.throws(() => ow('foo' as any, ow.float64Array), 'Expected argument to be of type `Float64Array` but received type `string`'); + t.throws(() => ow(12 as any, ow.float64Array), 'Expected argument to be of type `Float64Array` but received type `number`'); }); diff --git a/source/test/undefined.ts b/source/test/undefined.ts index 9966025..756ad2a 100644 --- a/source/test/undefined.ts +++ b/source/test/undefined.ts @@ -1,15 +1,15 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('undefined', t => { const x = undefined; const y = 12; - t.notThrows(() => m(undefined, m.undefined)); - t.notThrows(() => m(x, m.undefined)); - t.notThrows(() => m(x, 'foo', m.undefined)); - t.throws(() => m(y as any, m.undefined), 'Expected `y` to be of type `undefined` but received type `number`'); - t.throws(() => m(y as any, 'foo', m.undefined), 'Expected `foo` to be of type `undefined` but received type `number`'); - t.throws(() => m(null as any, m.undefined), 'Expected argument to be of type `undefined` but received type `null`'); - t.throws(() => m('foo' as any, m.undefined), 'Expected argument to be of type `undefined` but received type `string`'); + t.notThrows(() => ow(undefined, ow.undefined)); + t.notThrows(() => ow(x, ow.undefined)); + t.notThrows(() => ow(x, 'foo', ow.undefined)); + t.throws(() => ow(y as any, ow.undefined), 'Expected `y` to be of type `undefined` but received type `number`'); + t.throws(() => ow(y as any, 'foo', ow.undefined), 'Expected `foo` to be of type `undefined` but received type `number`'); + t.throws(() => ow(null as any, ow.undefined), 'Expected argument to be of type `undefined` but received type `null`'); + t.throws(() => ow('foo' as any, ow.undefined), 'Expected argument to be of type `undefined` but received type `string`'); }); diff --git a/source/test/weak-map.ts b/source/test/weak-map.ts index 2c7f980..e5bd761 100644 --- a/source/test/weak-map.ts +++ b/source/test/weak-map.ts @@ -1,11 +1,11 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; test('weakMap', t => { - t.notThrows(() => m(new WeakMap(), m.weakMap)); - t.notThrows(() => m(new WeakMap([[{foo: 'bar'}, '🦄']]), m.weakMap)); - t.throws(() => m(12 as any, m.weakMap), 'Expected argument to be of type `WeakMap` but received type `number`'); - t.throws(() => m(12 as any, 'foo', m.weakMap), 'Expected `foo` to be of type `WeakMap` but received type `number`'); + t.notThrows(() => ow(new WeakMap(), ow.weakMap)); + t.notThrows(() => ow(new WeakMap([[{foo: 'bar'}, '🦄']]), ow.weakMap)); + t.throws(() => ow(12 as any, ow.weakMap), 'Expected argument to be of type `WeakMap` but received type `number`'); + t.throws(() => ow(12 as any, 'foo', ow.weakMap), 'Expected `foo` to be of type `WeakMap` but received type `number`'); }); test('weakMap.hasKeys', t => { @@ -13,11 +13,11 @@ test('weakMap.hasKeys', t => { const rainbow = {rainbow: true}; const keys = [{x: 1}, {x: 2}, {x: 3}, {x: 4}, {x: 5}, {x: 6}, {x: 7}, {x: 8}, {x: 9}, {x: 10}]; - t.notThrows(() => m(new WeakMap([[unicorn, '🦄']]), m.weakMap.hasKeys(unicorn))); - t.throws(() => m(new WeakMap([[{rainbow: true}, '🌈']]), m.weakMap.hasKeys({rainbow: true})), 'Expected WeakMap to have keys `[{"rainbow":true}]`'); - t.throws(() => m(new WeakMap([[{rainbow: true}, '🌈']]), 'foo', m.weakMap.hasKeys({rainbow: true})), 'Expected WeakMap `foo` to have keys `[{"rainbow":true}]`'); - t.throws(() => m(new WeakMap([[unicorn, '🦄'], [rainbow, '🌈']]), m.weakMap.hasKeys(unicorn, {rainbow: true})), 'Expected WeakMap to have keys `[{"rainbow":true}]`'); - t.throws(() => m(new WeakMap([[keys[0], 1], [keys[2], 3]]), m.weakMap.hasKeys(...keys)), 'Expected WeakMap to have keys `[{"x":2},{"x":4},{"x":5},{"x":6},{"x":7}]`'); + t.notThrows(() => ow(new WeakMap([[unicorn, '🦄']]), ow.weakMap.hasKeys(unicorn))); + t.throws(() => ow(new WeakMap([[{rainbow: true}, '🌈']]), ow.weakMap.hasKeys({rainbow: true})), 'Expected WeakMap to have keys `[{"rainbow":true}]`'); + t.throws(() => ow(new WeakMap([[{rainbow: true}, '🌈']]), 'foo', ow.weakMap.hasKeys({rainbow: true})), 'Expected WeakMap `foo` to have keys `[{"rainbow":true}]`'); + t.throws(() => ow(new WeakMap([[unicorn, '🦄'], [rainbow, '🌈']]), ow.weakMap.hasKeys(unicorn, {rainbow: true})), 'Expected WeakMap to have keys `[{"rainbow":true}]`'); + t.throws(() => ow(new WeakMap([[keys[0], 1], [keys[2], 3]]), ow.weakMap.hasKeys(...keys)), 'Expected WeakMap to have keys `[{"x":2},{"x":4},{"x":5},{"x":6},{"x":7}]`'); }); test('weakMap.hasAnyKeys', t => { @@ -25,8 +25,8 @@ test('weakMap.hasAnyKeys', t => { const rainbow = {rainbow: true}; const rocket = {rocket: true}; - t.notThrows(() => m(new WeakMap([[unicorn, '🦄']]), m.weakMap.hasAnyKeys(unicorn, rainbow))); - t.notThrows(() => m(new WeakMap([[unicorn, '🦄'], [rainbow, '🌈']]), m.weakMap.hasAnyKeys(unicorn))); - t.notThrows(() => m(new WeakMap([[unicorn, '🦄'], [rainbow, '🌈']]), m.weakMap.hasAnyKeys(unicorn, rainbow, rocket))); - t.throws(() => m(new WeakMap([[unicorn, '🦄'], [rainbow, '🌈']]), m.weakMap.hasAnyKeys(rocket)), 'Expected WeakMap to have any key of `[{"rocket":true}]`'); + t.notThrows(() => ow(new WeakMap([[unicorn, '🦄']]), ow.weakMap.hasAnyKeys(unicorn, rainbow))); + t.notThrows(() => ow(new WeakMap([[unicorn, '🦄'], [rainbow, '🌈']]), ow.weakMap.hasAnyKeys(unicorn))); + t.notThrows(() => ow(new WeakMap([[unicorn, '🦄'], [rainbow, '🌈']]), ow.weakMap.hasAnyKeys(unicorn, rainbow, rocket))); + t.throws(() => ow(new WeakMap([[unicorn, '🦄'], [rainbow, '🌈']]), ow.weakMap.hasAnyKeys(rocket)), 'Expected WeakMap to have any key of `[{"rocket":true}]`'); }); diff --git a/source/test/weak-set.ts b/source/test/weak-set.ts index c424539..32edff4 100644 --- a/source/test/weak-set.ts +++ b/source/test/weak-set.ts @@ -1,31 +1,31 @@ import test from 'ava'; -import m from '..'; +import ow from '..'; const unicorn = {unicorn: '🦄'}; const rainbow = {rainbow: '🌈'}; const rocket = {rocket: '🚀'}; test('weakSet', t => { - t.notThrows(() => m(new WeakSet(), m.weakSet)); - t.notThrows(() => m(new WeakSet([{unicorn: '🦄'}]), m.weakSet)); - t.notThrows(() => m(new WeakSet([unicorn]), m.weakSet)); - t.throws(() => m(12 as any, m.weakSet), 'Expected argument to be of type `WeakSet` but received type `number`'); - t.throws(() => m(12 as any, 'foo', m.weakSet), 'Expected `foo` to be of type `WeakSet` but received type `number`'); + t.notThrows(() => ow(new WeakSet(), ow.weakSet)); + t.notThrows(() => ow(new WeakSet([{unicorn: '🦄'}]), ow.weakSet)); + t.notThrows(() => ow(new WeakSet([unicorn]), ow.weakSet)); + t.throws(() => ow(12 as any, ow.weakSet), 'Expected argument to be of type `WeakSet` but received type `number`'); + t.throws(() => ow(12 as any, 'foo', ow.weakSet), 'Expected `foo` to be of type `WeakSet` but received type `number`'); }); test('weakSet.has', t => { const keys = [{x: 1}, {x: 2}, {x: 3}, {x: 4}, {x: 5}, {x: 6}, {x: 7}, {x: 8}, {x: 9}, {x: 10}]; - t.notThrows(() => m(new WeakSet([unicorn]), m.weakSet.has(unicorn))); - t.notThrows(() => m(new WeakSet([unicorn, rainbow]), m.weakSet.has(unicorn, rainbow))); - t.throws(() => m(new WeakSet([unicorn, rainbow]), m.weakSet.has(rocket)), 'Expected WeakSet to have items `[{"rocket":"🚀"}]`'); - t.throws(() => m(new WeakSet([unicorn, rainbow]), 'foo', m.weakSet.has(rocket)), 'Expected WeakSet `foo` to have items `[{"rocket":"🚀"}]`'); - t.throws(() => m(new WeakSet([unicorn, rocket]), m.weakSet.has(rainbow, rocket)), 'Expected WeakSet to have items `[{"rainbow":"🌈"}]`'); - t.throws(() => m(new WeakSet([keys[1], keys[3]]), m.weakSet.has(...keys)), 'Expected WeakSet to have items `[{"x":1},{"x":3},{"x":5},{"x":6},{"x":7}]`'); + t.notThrows(() => ow(new WeakSet([unicorn]), ow.weakSet.has(unicorn))); + t.notThrows(() => ow(new WeakSet([unicorn, rainbow]), ow.weakSet.has(unicorn, rainbow))); + t.throws(() => ow(new WeakSet([unicorn, rainbow]), ow.weakSet.has(rocket)), 'Expected WeakSet to have items `[{"rocket":"🚀"}]`'); + t.throws(() => ow(new WeakSet([unicorn, rainbow]), 'foo', ow.weakSet.has(rocket)), 'Expected WeakSet `foo` to have items `[{"rocket":"🚀"}]`'); + t.throws(() => ow(new WeakSet([unicorn, rocket]), ow.weakSet.has(rainbow, rocket)), 'Expected WeakSet to have items `[{"rainbow":"🌈"}]`'); + t.throws(() => ow(new WeakSet([keys[1], keys[3]]), ow.weakSet.has(...keys)), 'Expected WeakSet to have items `[{"x":1},{"x":3},{"x":5},{"x":6},{"x":7}]`'); }); test('weakSet.hasAny', t => { - t.notThrows(() => m(new WeakSet([unicorn]), m.weakSet.hasAny(unicorn, rainbow))); - t.notThrows(() => m(new WeakSet([unicorn, rainbow]), m.weakSet.hasAny(unicorn))); - t.throws(() => m(new WeakSet([unicorn, rainbow]), m.weakSet.hasAny(rocket)), 'Expected WeakSet to have any item of `[{"rocket":"🚀"}]`'); + t.notThrows(() => ow(new WeakSet([unicorn]), ow.weakSet.hasAny(unicorn, rainbow))); + t.notThrows(() => ow(new WeakSet([unicorn, rainbow]), ow.weakSet.hasAny(unicorn))); + t.throws(() => ow(new WeakSet([unicorn, rainbow]), ow.weakSet.hasAny(rocket)), 'Expected WeakSet to have any item of `[{"rocket":"🚀"}]`'); });