-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
test.js
81 lines (65 loc) · 1.51 KB
/
test.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* eslint-disable no-new-wrappers, unicorn/new-for-builtins, no-array-constructor, prefer-rest-params, n/prefer-global/buffer */
const test = require('ava');
const type = require('./index.js');
test('objects', t => {
function Foo() {}
t.is(type({}), 'object');
t.is(type(new Foo()), 'object');
});
test('numbers', t => {
t.is(type(12), 'number');
t.is(type(1), 'number');
t.is(type(-5), 'number');
t.is(type(new Number(123)), 'number');
t.is(type(Number.POSITIVE_INFINITY), 'number');
});
test('NaN', t => {
t.is(type(Number.NaN), 'nan');
});
test('strings', t => {
t.is(type('test'), 'string');
t.is(type(new String('whoop')), 'string');
});
test('dates', t => {
t.is(type(new Date()), 'date');
});
test('booleans', t => {
t.is(type(true), 'boolean');
t.is(type(false), 'boolean');
t.is(type(new Boolean(true)), 'boolean');
});
test('null', t => {
t.is(type(null), 'null');
});
test('undefined', t => {
t.is(type(), 'undefined');
t.is(type(undefined), 'undefined');
});
test('arrays', t => {
t.is(type([]), 'array');
t.is(type(new Array()), 'array');
});
test('regexps', t => {
t.is(type(/asdf/), 'regexp');
});
test('functions', t => {
t.is(type(() => {}), 'function');
});
test('arguments', t => {
(function () {
t.is(type(arguments), 'arguments');
})();
});
test('elements', t => {
const foo = {
key: 'OK',
nodeType: 1,
};
t.not(type(foo), 'element');
});
test('errors', t => {
t.is(type(new Error('Ups!')), 'error');
});
test('buffers', t => {
t.is(type(Buffer.alloc(4)), 'buffer');
});