-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
94 lines (75 loc) · 2.09 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
'use strict';
const is = require('.');
test('is.array', () => {
expect(is.array([])).toBe(true);
expect(is.array({})).toBe(false);
});
test('is.string', () => {
expect(is.string('')).toBe(true);
expect(is.string({})).toBe(false);
});
test('is.symbol', () => {
expect(is.symbol(Symbol())).toBe(true);
expect(is.symbol('Symbol()')).toBe(false);
});
test('is.function', () => {
expect(is.function(() => {})).toBe(true);
});
test('is.boolean', () => {
expect(is.boolean(true)).toBe(true);
expect(is.bool(false)).toBe(true);
});
test('is.undefined', () => {
expect(is.undefined(undefined)).toBe(true);
expect(is.undef(undefined)).toBe(true);
});
test('is.NaN', () => {
expect(is.NaN(NaN)).toBe(true);
expect(is.nan(NaN)).toBe(true);
});
test('is.finite', () => {
expect(is.finite(Infinity)).toBe(false);
});
test('is.number', () => {
expect(is.number(1.1)).toBe(true);
expect(is.number('1.1')).toBe(false);
});
test('is.null', () => {
expect(is.null(null)).toBe(true);
});
test('is.regexp', () => {
expect(is.regexp(/^$/)).toBe(true);
});
test('is.date', () => {
expect(is.date(new Date())).toBe(true);
});
test('is.error', () => {
expect(is.error(new Error())).toBe(true);
});
test('is.object', () => {
expect(is.object(null)).toBe(false);
expect(is.object({})).toBe(true);
});
test('is.buffer', () => {
expect(is.buffer(Buffer.from([]))).toBe(true);
});
test('is.primitive', () => {
expect(is.primitive(null)).toBe(true);
expect(is.primitive('')).toBe(true);
expect(is.primitive(0)).toBe(true);
expect(is.primitive(undefined)).toBe(true);
expect(is.primitive(true)).toBe(true);
expect(is.primitive(Symbol())).toBe(true);
});
test('is.alphanum', () => {
expect(is.alphanum(1)).toBe(true);
expect(is.alphanum('')).toBe(false);
expect(is.alphanum('1')).toBe(true);
expect(is.alphanum('1a')).toBe(true);
expect(is.alphanum('1%')).toBe(false);
});
test('is.validPhoneNumber', () => {
expect(is.validPhoneNumber('15200000000')).toBe(true);
expect(is.validPhoneNumber('1520000000')).toBe(false);
expect(is.validPhoneNumber('2520000000')).toBe(false);
});