-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathis-typed-array.test.js
More file actions
57 lines (52 loc) · 1.88 KB
/
is-typed-array.test.js
File metadata and controls
57 lines (52 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// @ts-check
import test from 'ava';
import '../index.js';
import { isTypedArray } from '../src/make-hardener.js';
// Tests borrowed from https://github.com/inspect-js/is-typed-array
// https://github.com/inspect-js/is-typed-array/blob/c1ad8eae617870e3b3700dda0ff736a267b7e990/LICENSE
// MIT license.
test('isTypedArray positive cases', t => {
t.assert(isTypedArray(new Int8Array()));
t.assert(isTypedArray(new Uint8Array()));
t.assert(isTypedArray(new Uint8ClampedArray()));
t.assert(isTypedArray(new Int16Array()));
t.assert(isTypedArray(new Uint16Array()));
t.assert(isTypedArray(new Int32Array()));
t.assert(isTypedArray(new Uint32Array()));
if (typeof Float16Array !== 'undefined') {
// https://github.com/tc39/proposal-float16array
t.assert(isTypedArray(new Float16Array()));
}
t.assert(isTypedArray(new Float32Array()));
t.assert(isTypedArray(new Float64Array()));
t.assert(isTypedArray(new BigInt64Array()));
t.assert(isTypedArray(new BigUint64Array()));
});
test('isTypedArray negative cases', t => {
t.assert(!isTypedArray(undefined));
t.assert(!isTypedArray(null));
t.assert(!isTypedArray(false));
t.assert(!isTypedArray(true));
t.assert(!isTypedArray([]));
t.assert(!isTypedArray({}));
t.assert(!isTypedArray(/a/g));
t.assert(!isTypedArray(new RegExp('a', 'g')));
t.assert(!isTypedArray(new Date()));
t.assert(!isTypedArray(42));
t.assert(!isTypedArray(NaN));
t.assert(!isTypedArray(Infinity));
// eslint-disable-next-line no-new-wrappers
t.assert(!isTypedArray(new Number(42)));
t.assert(!isTypedArray('foo'));
t.assert(!isTypedArray(Object('foo')));
// eslint-disable-next-line prefer-arrow-callback
t.assert(!isTypedArray(function f() {}));
t.assert(
!isTypedArray(function* g() {
yield;
}),
);
t.assert(!isTypedArray(() => {}));
t.assert(!isTypedArray([]));
t.assert(!isTypedArray(new ArrayBuffer(1)));
});