mirror of https://github.com/lukechilds/ow.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
159 lines
4.0 KiB
159 lines
4.0 KiB
7 years ago
|
import test from 'ava';
|
||
6 years ago
|
import ow from '../source';
|
||
7 years ago
|
|
||
|
test('typedArray', t => {
|
||
6 years ago
|
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`');
|
||
7 years ago
|
});
|
||
|
|
||
|
test('int8Array', t => {
|
||
6 years ago
|
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`');
|
||
7 years ago
|
});
|
||
|
|
||
|
test('uint8Array', t => {
|
||
6 years ago
|
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`');
|
||
7 years ago
|
});
|
||
|
|
||
|
test('uint8ClampedArray', t => {
|
||
6 years ago
|
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`');
|
||
7 years ago
|
});
|
||
|
|
||
|
test('int16Array', t => {
|
||
6 years ago
|
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`');
|
||
7 years ago
|
});
|
||
|
|
||
|
test('uint16Array', t => {
|
||
6 years ago
|
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`');
|
||
7 years ago
|
});
|
||
|
|
||
|
test('int32Array', t => {
|
||
6 years ago
|
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`');
|
||
7 years ago
|
});
|
||
|
|
||
|
test('uint32Array', t => {
|
||
6 years ago
|
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`');
|
||
7 years ago
|
});
|
||
|
|
||
|
test('float32Array', t => {
|
||
6 years ago
|
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`');
|
||
7 years ago
|
});
|
||
|
|
||
|
test('float64Array', t => {
|
||
6 years ago
|
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`');
|
||
7 years ago
|
});
|