-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathis.test.ts
More file actions
94 lines (80 loc) · 2.67 KB
/
is.test.ts
File metadata and controls
94 lines (80 loc) · 2.67 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
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
import {
isArray,
isBoolean,
isDate,
isNull,
isNumber,
isPrimitive,
isRegExp,
isString,
isSymbol,
isUndefined,
isPlainObject,
isTypedArray,
isURL,
} from './is.js';
import { test, expect } from 'vitest';
test('Basic true tests', () => {
expect(isUndefined(undefined)).toBe(true);
expect(isNull(null)).toBe(true);
expect(isArray([])).toBe(true);
expect(isArray([])).toBe(true);
expect(isString('')).toBe(true);
expect(isString('_')).toBe(true);
expect(isBoolean(true)).toBe(true);
expect(isBoolean(false)).toBe(true);
expect(isRegExp(/./)).toBe(true);
expect(isRegExp(/./gi)).toBe(true);
expect(isNumber(0)).toBe(true);
expect(isNumber(1)).toBe(true);
expect(isDate(new Date())).toBe(true);
expect(isSymbol(Symbol())).toBe(true);
expect(isTypedArray(new Uint8Array())).toBe(true);
expect(isURL(new URL('https://example.com'))).toBe(true);
expect(isPlainObject({})).toBe(true);
// eslint-disable-next-line no-object-constructor
expect(isPlainObject(new Object())).toBe(true);
});
test('Basic false tests', () => {
expect(isNumber(NaN)).toBe(false);
expect(isDate(new Date('_'))).toBe(false);
expect(isDate(NaN)).toBe(false);
expect(isUndefined(NaN)).toBe(false);
expect(isNull(NaN)).toBe(false);
expect(isArray(NaN)).toBe(false);
expect(isString(NaN)).toBe(false);
expect(isBoolean(NaN)).toBe(false);
expect(isRegExp(NaN)).toBe(false);
expect(isSymbol(NaN)).toBe(false);
expect(isTypedArray([])).toBe(false);
expect(isURL('https://example.com')).toBe(false);
expect(isPlainObject(null)).toBe(false);
expect(isPlainObject([])).toBe(false);
expect(isPlainObject(Object.prototype)).toBe(false);
expect(isPlainObject(Object.create(Array.prototype))).toBe(false);
});
test('Primitive tests', () => {
expect(isPrimitive(0)).toBe(true);
expect(isPrimitive('')).toBe(true);
expect(isPrimitive('str')).toBe(true);
expect(isPrimitive(Symbol())).toBe(true);
expect(isPrimitive(true)).toBe(true);
expect(isPrimitive(false)).toBe(true);
expect(isPrimitive(null)).toBe(true);
expect(isPrimitive(undefined)).toBe(true);
expect(isPrimitive(NaN)).toBe(false);
expect(isPrimitive([])).toBe(false);
expect(isPrimitive([])).toBe(false);
expect(isPrimitive({})).toBe(false);
// eslint-disable-next-line no-object-constructor
expect(isPrimitive(new Object())).toBe(false);
expect(isPrimitive(new Date())).toBe(false);
expect(isPrimitive(() => {})).toBe(false);
});
test('Date exception', () => {
expect(isDate(new Date('_'))).toBe(false);
});
test('Regression: null-prototype object', () => {
expect(isPlainObject(Object.create(null))).toBe(true);
expect(isPrimitive(Object.create(null))).toBe(false);
});