-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathutil.test.js
64 lines (52 loc) · 2.16 KB
/
util.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
/**
* All tests that tests any utility.
* Prevent any breaking of functionality
*/
import assert from 'assert';
import typeOf from '../src/lib/util/typeOf';
import assertString from '../src/lib/util/assertString';
describe('Util', () => {
it('should validate different typeOf', () => {
assert.strictEqual(typeOf([]), 'array');
assert.strictEqual(typeOf(null), 'null');
assert.strictEqual(typeOf({}), 'object');
assert.strictEqual(typeOf(new Date()), 'date');
assert.strictEqual(typeOf('ezkemboi'), 'string');
assert.strictEqual(typeOf(String('kemboi')), 'string');
assert.strictEqual(typeOf(undefined), 'undefined');
assert.strictEqual(typeOf(2021), 'number');
assert.notStrictEqual(typeOf([]), 'object');
});
});
describe('assertString', () => {
it('Should throw an error if argument provided is an undefined', () => {
assert.throws(() => { assertString(); }, TypeError);
});
it('Should throw an error if argument provided is a null', () => {
assert.throws(() => { assertString(null); }, TypeError);
});
it('Should throw an error if argument provided is a Boolean', () => {
assert.throws(() => { assertString(true); }, TypeError);
});
it('Should throw an error if argument provided is a Date', () => {
assert.throws(() => { assertString(new Date()); }, TypeError);
});
it('Should throw an error if argument provided is a Number(NaN)', () => {
assert.throws(() => { assertString(NaN); }, TypeError);
});
it('Should throw an error if argument provided is a Number', () => {
assert.throws(() => { assertString(2024); }, TypeError);
});
it('Should throw an error if argument provided is an Object', () => {
assert.throws(() => { assertString({}); }, TypeError);
});
it('Should throw an error if argument provided is an Array', () => {
assert.throws(() => { assertString([]); }, TypeError);
});
it('Should not throw an error if the argument is an empty string', () => {
assert.doesNotThrow(() => { assertString(''); });
});
it('Should not throw an error if the argument is a String', () => {
assert.doesNotThrow(() => { assertString('antidisestablishmentarianism'); });
});
});