1 import expect from
'expect';
3 import Utils from
'../../src/utils/Utils';
5 describe('Utils test suite', () => {
6 it('Verify generateUUID()/validateUUID()', () => {
7 const uuid
= Utils
.generateUUID();
8 expect(uuid
.length
).toEqual(36);
9 expect(Utils
.validateUUID(uuid
)).toBe(true);
12 it('Verify secureRandom()', () => {
13 const random
= Utils
.secureRandom();
14 expect(typeof random
=== 'number').toBe(true);
15 expect(random
).toBeGreaterThanOrEqual(0);
16 expect(random
).toBeLessThan(1);
19 it('Verify getRandomInteger()', () => {
20 const randomInteger
= Utils
.getRandomInteger();
21 expect(Number.isSafeInteger(randomInteger
)).toBe(true);
22 expect(randomInteger
).toBeGreaterThanOrEqual(0);
23 expect(randomInteger
).toBeLessThanOrEqual(Number.MAX_SAFE_INTEGER
);
24 expect(() => Utils
.getRandomInteger(0, 1)).toThrowError(new RangeError('Invalid interval'));
25 expect(() => Utils
.getRandomInteger(-1)).toThrowError(new RangeError('Invalid interval'));
26 expect(() => Utils
.getRandomInteger(0, -1)).toThrowError(new RangeError('Invalid interval'));
29 it('Verify getRandomFloat()', () => {
30 const randomFloat
= Utils
.getRandomFloat();
31 expect(typeof randomFloat
=== 'number').toBe(true);
32 expect(randomFloat
).toBeGreaterThanOrEqual(0);
33 expect(randomFloat
).toBeLessThanOrEqual(Number.MAX_VALUE
);
34 expect(() => Utils
.getRandomFloat(0, 1)).toThrowError(new RangeError('Invalid interval'));
35 expect(() => Utils
.getRandomFloat(-1)).toThrowError(new RangeError('Invalid interval'));
36 expect(() => Utils
.getRandomFloat(0, -1)).toThrowError(new RangeError('Invalid interval'));
39 it('Verify isIterable()', () => {
40 expect(Utils
.isIterable('')).toBe(false);
41 expect(Utils
.isIterable(' ')).toBe(true);
42 expect(Utils
.isIterable('test')).toBe(true);
43 expect(Utils
.isIterable(null)).toBe(false);
44 expect(Utils
.isIterable(undefined)).toBe(false);
45 expect(Utils
.isIterable(0)).toBe(false);
46 expect(Utils
.isIterable({})).toBe(false);
47 expect(Utils
.isIterable({ 1: 1 })).toBe(false);
48 expect(Utils
.isIterable([])).toBe(true);
49 expect(Utils
.isIterable(new Map())).toBe(true);
50 expect(Utils
.isIterable(new Set())).toBe(true);
51 expect(Utils
.isIterable(new WeakMap())).toBe(false);
52 expect(Utils
.isIterable(new WeakSet())).toBe(false);
55 it('Verify isEmptyString()', () => {
56 expect(Utils
.isEmptyString('')).toBe(true);
57 expect(Utils
.isEmptyString(' ')).toBe(true);
58 expect(Utils
.isEmptyString(' ')).toBe(true);
59 expect(Utils
.isEmptyString('test')).toBe(false);
60 expect(Utils
.isEmptyString(' test')).toBe(false);
61 expect(Utils
.isEmptyString('test ')).toBe(false);
62 expect(Utils
.isEmptyString(null)).toBe(false);
63 expect(Utils
.isEmptyString(undefined)).toBe(false);
64 expect(Utils
.isEmptyString(0)).toBe(false);
65 expect(Utils
.isEmptyString({})).toBe(false);
66 expect(Utils
.isEmptyString([])).toBe(false);
67 expect(Utils
.isEmptyString(new Map())).toBe(false);
68 expect(Utils
.isEmptyString(new Set())).toBe(false);
71 it('Verify isNullOrUndefined()', () => {
72 expect(Utils
.isNullOrUndefined(null)).toBe(true);
73 expect(Utils
.isNullOrUndefined(undefined)).toBe(true);
74 expect(Utils
.isNullOrUndefined('')).toBe(false);
75 expect(Utils
.isNullOrUndefined(0)).toBe(false);
76 expect(Utils
.isNullOrUndefined({})).toBe(false);
77 expect(Utils
.isNullOrUndefined([])).toBe(false);
78 expect(Utils
.isNullOrUndefined(new Map())).toBe(false);
79 expect(Utils
.isNullOrUndefined(new Set())).toBe(false);
82 it('Verify isEmptyArray()', () => {
83 expect(Utils
.isEmptyArray([])).toBe(true);
84 expect(Utils
.isEmptyArray([1, 2])).toBe(false);
85 expect(Utils
.isEmptyArray(null)).toBe(false);
86 expect(Utils
.isEmptyArray(undefined)).toBe(false);
87 expect(Utils
.isEmptyArray('')).toBe(false);
88 expect(Utils
.isEmptyArray(0)).toBe(false);
89 expect(Utils
.isEmptyArray({})).toBe(false);
90 expect(Utils
.isEmptyArray(new Map())).toBe(false);
91 expect(Utils
.isEmptyArray(new Set())).toBe(false);
94 it('Verify isEmptyObject()', () => {
95 expect(Utils
.isEmptyObject({})).toBe(true);
96 expect(Utils
.isEmptyObject({ 1: 1, 2: 2 })).toBe(false);
97 expect(Utils
.isEmptyObject(null)).toBe(false);
98 expect(Utils
.isEmptyObject(undefined)).toBe(false);
99 expect(Utils
.isEmptyObject(new Map())).toBe(false);
100 expect(Utils
.isEmptyObject(new Set())).toBe(false);