-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
116 lines (91 loc) · 2.63 KB
/
index.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const vartype = require('./index');
test('undefined', () => {
expect(vartype(undefined)).toBe('undefined');
expect(vartype(undefined, true)).toBe('undefined');
});
test('null', () => {
expect(vartype(null)).toBe('null');
expect(vartype(null, true)).toBe('null');
});
test('boolean', () => {
expect(vartype(true)).toBe('boolean');
expect(vartype(true, true)).toBe('boolean');
});
test('string', () => {
expect(vartype('a')).toBe('string');
expect(vartype('a', true)).toBe('string');
});
test('nan', () => {
expect(vartype(NaN)).toBe('nan');
expect(vartype(NaN, true)).toBe('nan');
});
test('infinity', () => {
expect(vartype(Infinity)).toBe('infinity');
expect(vartype(Infinity, true)).toBe('infinity');
});
test('integer', () => {
expect(vartype(123)).toBe('number');
expect(vartype(123, true)).toBe('integer');
});
test('float', () => {
expect(vartype(1.5)).toBe('number');
expect(vartype(1.5, true)).toBe('float');
});
test('double', () => {
expect(vartype(1.4)).toBe('number');
expect(vartype(1.4, true)).toBe('double');
});
test('function', () => {
expect(vartype(() => {})).toBe('function');
expect(vartype(() => {}, true)).toBe('function');
});
test('symbol', () => {
expect(vartype(Symbol('test'))).toBe('symbol');
expect(vartype(Symbol('test'), true)).toBe('symbol');
});
test('object', () => {
expect(vartype({})).toBe('object');
expect(vartype({}, true)).toBe('object');
});
test('array', () => {
expect(vartype([])).toBe('array');
expect(vartype([], true)).toBe('array');
});
test('error', () => {
expect(vartype(new Error('test'))).toBe('object');
expect(vartype(new Error('test'), true)).toBe('error');
});
test('promise', () => {
const promise = new Promise((resolve) => setTimeout(resolve, 5));
expect(vartype(promise, true)).toBe('promise');
});
test('date', () => {
expect(vartype(new Date(), true)).toBe('date');
});
test('regexp', () => {
expect(vartype(/asd/, true)).toBe('regexp');
});
test('map', () => {
expect(vartype(new Map(), true)).toBe('map');
});
test('set', () => {
expect(vartype(new Set(), true)).toBe('set');
});
test('weakmap', () => {
expect(vartype(new WeakMap(), true)).toBe('weakmap');
});
test('weakset', () => {
expect(vartype(new WeakSet(), true)).toBe('weakset');
});
test('arraybuffer', () => {
expect(vartype(new ArrayBuffer(), true)).toBe('arraybuffer');
});
test('dataview', () => {
expect(vartype(new DataView(new ArrayBuffer()), true)).toBe('dataview');
});
test('int8array', () => {
expect(vartype(new Int8Array(), true)).toBe('int8array');
});
test('uint8array', () => {
expect(vartype(new Uint8Array(), true)).toBe('uint8array');
});