-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathis.tests.js
More file actions
113 lines (97 loc) · 3.5 KB
/
is.tests.js
File metadata and controls
113 lines (97 loc) · 3.5 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* eslint-disable no-undefined */
'use strict';
const expect = require('chai').expect;
const is = require('../src/helper/is');
const { Configuration } = require('..');
describe('is test case', function () {
it('test case for undefined', async function () {
let data = {};
expect(is.undefined(data.undefined)).to.be.true;
data = [];
expect(is.undefined(data[0])).to.be.true;
expect(is.undefined(undefined)).to.be.true;
});
it('test case for array', function () {
expect(is.array([])).to.be.true;
expect(is.array({})).to.be.false;
expect(is.array(undefined)).to.be.false;
expect(is.array(null)).to.be.false;
expect(is.array('')).to.be.false;
});
it('test case for string', function () {
expect(is.string('')).to.be.true;
expect(is.string(0)).to.be.false;
expect(is.string({})).to.be.false;
});
it('test case for number', function () {
expect(is.number(1.123)).to.be.true;
// eslint-disable-next-line no-loss-of-precision
expect(is.number(1111111111111111111111111)).to.be.true;
expect(is.number('123')).to.be.false;
Number.isFinite = undefined;
expect(is.number('123')).to.be.false;
});
it('test case for integer', function () {
expect(is.integer(1.123)).to.be.false;
// eslint-disable-next-line no-loss-of-precision
expect(is.integer(1111111111111111111111111)).to.be.true;
expect(is.integer('123')).to.be.false;
});
it('test case for numeric', function () {
expect(is.numeric(1)).to.be.true;
expect(is.numeric('1.23')).to.be.true;
expect(is.numeric('60s')).to.be.false;
expect(is.numeric('')).to.be.false;
expect(is.numeric('0')).to.be.true;
expect(is.numeric(0)).to.be.true;
expect(is.numeric(null)).to.be.false;
expect(is.numeric(-Infinity)).to.be.false;
expect(is.numeric(Infinity)).to.be.false;
expect(is.numeric(NaN)).to.be.false;
expect(is.numeric({})).to.be.false;
});
it('test case for object', function () {
expect(is.object({})).to.be.true;
let obj = {};
expect(is.object(obj)).to.be.true;
expect(is.object([])).to.be.false;
const config = new Configuration();
expect(is.object(config)).to.be.true;
});
it('test case for function', function () {
expect(is.func(function name() { })).to.be.true;
const func = function () { return; };
expect(is.func(func)).to.be.true;
const config = new Configuration();
expect(is.func(config.get)).to.be.true;
});
it('test case for boolean', function () {
expect(is.boolean(true)).to.be.true;
expect(is.boolean(false)).to.be.true;
});
it('test case for file&dir', async function () {
expect(await is.file(__filename)).to.be.true;
expect(await is.file(__dirname)).to.be.false;
expect(await is.dir(__dirname)).to.be.true;
expect(await is.dir(__filename)).to.be.false;
});
it('test case for invalid', function () {
expect(is.invalid(null)).to.be.true;
expect(is.invalid(undefined)).to.be.true;
expect(is.invalid('')).to.be.false;
});
it('test case for contain', function () {
expect(is.contain(['a', 'b'], 'b')).to.be.true;
expect(is.contain('ab', 'b')).to.be.true;
expect(is.contain({ b: 'B' }, 'b')).to.be.true;
expect(is.contain('ab', 'c')).to.be.false;
});
it('test case for empty', function () {
expect(is.empty('')).to.be.true;
expect(is.empty([])).to.be.true;
expect(is.empty({})).to.be.true;
expect(is.empty(undefined)).to.be.true;
expect(is.empty(null)).to.be.true;
expect(is.empty(0)).to.be.false;
});
});