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
).toBeDefined();
9 expect(uuid
.length
).toEqual(36);
10 expect(Utils
.validateUUID(uuid
)).toBe(true);
11 expect(Utils
.validateUUID('abcdef00-0000-4000-0000-000000000000')).toBe(true);
12 expect(Utils
.validateUUID('')).toBe(false);
13 expect(Utils
.validateUUID('987FBC9-4BED-3078-CF07A-9141BA07C9F3')).toBe(false);
16 it('Verify secureRandom()', () => {
17 const random
= Utils
.secureRandom();
18 expect(typeof random
=== 'number').toBe(true);
19 expect(random
).toBeGreaterThanOrEqual(0);
20 expect(random
).toBeLessThan(1);
23 it('Verify getRandomInteger()', () => {
24 const randomInteger
= Utils
.getRandomInteger();
25 expect(Number.isSafeInteger(randomInteger
)).toBe(true);
26 expect(randomInteger
).toBeGreaterThanOrEqual(0);
27 expect(randomInteger
).toBeLessThanOrEqual(Number.MAX_SAFE_INTEGER
);
28 expect(() => Utils
.getRandomInteger(0, 1)).toThrowError(new RangeError('Invalid interval'));
29 expect(() => Utils
.getRandomInteger(-1)).toThrowError(new RangeError('Invalid interval'));
30 expect(() => Utils
.getRandomInteger(0, -1)).toThrowError(new RangeError('Invalid interval'));
33 it('Verify getRandomFloat()', () => {
34 const randomFloat
= Utils
.getRandomFloat();
35 expect(typeof randomFloat
=== 'number').toBe(true);
36 expect(randomFloat
).toBeGreaterThanOrEqual(0);
37 expect(randomFloat
).toBeLessThanOrEqual(Number.MAX_VALUE
);
38 expect(() => Utils
.getRandomFloat(0, 1)).toThrowError(new RangeError('Invalid interval'));
39 expect(() => Utils
.getRandomFloat(-1)).toThrowError(new RangeError('Invalid interval'));
40 expect(() => Utils
.getRandomFloat(0, -1)).toThrowError(new RangeError('Invalid interval'));
43 it('Verify isIterable()', () => {
44 expect(Utils
.isIterable('')).toBe(false);
45 expect(Utils
.isIterable(' ')).toBe(true);
46 expect(Utils
.isIterable('test')).toBe(true);
47 expect(Utils
.isIterable(null)).toBe(false);
48 expect(Utils
.isIterable(undefined)).toBe(false);
49 expect(Utils
.isIterable(0)).toBe(false);
50 expect(Utils
.isIterable({})).toBe(false);
51 expect(Utils
.isIterable({ 1: 1 })).toBe(false);
52 expect(Utils
.isIterable([])).toBe(true);
53 expect(Utils
.isIterable(new Map())).toBe(true);
54 expect(Utils
.isIterable(new Set())).toBe(true);
55 expect(Utils
.isIterable(new WeakMap())).toBe(false);
56 expect(Utils
.isIterable(new WeakSet())).toBe(false);
59 it('Verify isEmptyString()', () => {
60 expect(Utils
.isEmptyString('')).toBe(true);
61 expect(Utils
.isEmptyString(' ')).toBe(true);
62 expect(Utils
.isEmptyString(' ')).toBe(true);
63 expect(Utils
.isEmptyString('test')).toBe(false);
64 expect(Utils
.isEmptyString(' test')).toBe(false);
65 expect(Utils
.isEmptyString('test ')).toBe(false);
66 expect(Utils
.isEmptyString(null)).toBe(false);
67 expect(Utils
.isEmptyString(undefined)).toBe(false);
68 expect(Utils
.isEmptyString(0)).toBe(false);
69 expect(Utils
.isEmptyString({})).toBe(false);
70 expect(Utils
.isEmptyString([])).toBe(false);
71 expect(Utils
.isEmptyString(new Map())).toBe(false);
72 expect(Utils
.isEmptyString(new Set())).toBe(false);
75 it('Verify isNullOrUndefined()', () => {
76 expect(Utils
.isNullOrUndefined(null)).toBe(true);
77 expect(Utils
.isNullOrUndefined(undefined)).toBe(true);
78 expect(Utils
.isNullOrUndefined('')).toBe(false);
79 expect(Utils
.isNullOrUndefined(0)).toBe(false);
80 expect(Utils
.isNullOrUndefined({})).toBe(false);
81 expect(Utils
.isNullOrUndefined([])).toBe(false);
82 expect(Utils
.isNullOrUndefined(new Map())).toBe(false);
83 expect(Utils
.isNullOrUndefined(new Set())).toBe(false);
86 it('Verify isEmptyArray()', () => {
87 expect(Utils
.isEmptyArray([])).toBe(true);
88 expect(Utils
.isEmptyArray([1, 2])).toBe(false);
89 expect(Utils
.isEmptyArray(null)).toBe(false);
90 expect(Utils
.isEmptyArray(undefined)).toBe(false);
91 expect(Utils
.isEmptyArray('')).toBe(false);
92 expect(Utils
.isEmptyArray(0)).toBe(false);
93 expect(Utils
.isEmptyArray({})).toBe(false);
94 expect(Utils
.isEmptyArray(new Map())).toBe(false);
95 expect(Utils
.isEmptyArray(new Set())).toBe(false);
98 it('Verify isEmptyObject()', () => {
99 expect(Utils
.isEmptyObject({})).toBe(true);
100 expect(Utils
.isEmptyObject({ 1: 1, 2: 2 })).toBe(false);
101 expect(Utils
.isEmptyObject(null)).toBe(false);
102 expect(Utils
.isEmptyObject(undefined)).toBe(false);
103 expect(Utils
.isEmptyObject(new Map())).toBe(false);
104 expect(Utils
.isEmptyObject(new Set())).toBe(false);